Org 1000
mov si,1100
mov di,1400
cld
mov bl,20h
next: lodsb
cmp al, bl
je exit
sub al,30h
cmp al,0ah
jc store
sub al,07h
store: stosb
jmp next
exit: hlt
As you did not specify, I will assume you are talking about three-bit binary-reflected gray code. The procedure for other possible codes and lengths would be similar.
The code table of three-bit gray code
D bin gray D'
0 000 000 0
1 001 001 1
2 010 011 3
3 011 010 2
4 100 110 6
5 101 111 7
6 110 101 5
7 111 100 4
The format of this table is:
Decimal number; bits B2,B1,B0 of natural binary number; bits G2,G1,G0 of binary number in gray code; decimal representation of the gray code number
To get natural binary numbers from the gray numbers, we need to follow the algorithm defined by the table:
( Dec' -> Dec )
zero stays zero
one stays one
three becomes two
two becomes three
six becomes four
seven becomes five
five becomes six
four becomes seven
Let us search for rules in the transformation, so our program can detect which number it is working with and how to change it to natural binary.
Both 0 and 1 don't change. Their shared property is 00 in the higher two bits.
3 and 2 change places. They both have 01 in higher two bits, and the program should toggle the lowest bit.
Next we have the circular changes 7 -> 5 -> 6 -> 4 -> 7. This is a bit trickier, but if we analyse their binary forms, we can see that any number that has 10 in its top two bits needs to have its low two bits toggled (ie. 100 becomes 111, and 101 becomes 110). Similarly, those numbers with 11 in top two bits need to have their middle bit set to 0 (ie. 110 becomes 100 and 111 becomes 101).
In essence, the program should check for the two higher bits, and depending on the values there, perform one of these four operations. That check can be done in several ways, depending on what you can do with your microcontroller. Perhaps the easiest would be using a mask to set all other bits to zero and analysing what's left.
// INCLUDE HEADER FILES NEEDED BY YOUR PROGRAM
// SOME LIBRARY FUNCTIONALITY MAY BE RESTRICTED
// DEFINE ANY FUNCTION NEEDED
// FUNCTION SIGNATURE BEGINS, THIS FUNCTION IS REQUIRED
int grayCheck(char term1, char term2)
{
// WRITE YOUR CODE HERE
}
// FUNCTION SIGNATURE ENDS
// DO NOT IMPLEMENT THE main( ) METHOD
int main()
{
//DO NOT CHANGE ANY CODE IN THIS FUNCTION
int a;
char c1,c2;
//ASSUME INPUT HAVE ALREADY BEEN TAKEN
a=grayCheck(c1, c2);
return 0;
}
Lda 8050h
cpi oah
jnc l1
adi 07h
adi 30h
sta 9000
hlt
just add 3 to the number which you want ti convert into gray code
45
Assembly language allows the developer to have almost total control over what the sequence of instructions will be when a program executes. A compiler tries to translate a high level language such as C++ into a series of instructions, but a good assembly language programmer may be able to optimize the sequence when a compiler cannot. Primarily assembly language is used for speed and optimal machine code.
High-level to binary is known as compilation or interpretation, depending on whether the entire program is converted at once (compilation) or only one statement at a time is converted (interpretation). There is no conversion from binary to high level -- it's one-way only.
binary language
binary language is the natural language of computer
binary language
1- Binary language 2- Assembly Language
1- Binary language 2- Assembly Language
1- Binary language 2- Assembly Language
sscanf, atoi, strtol, ...
In order to convert binary to hexadecimal using assembly language, the programmer must possess an understanding on boolean algebra or binary system in other words. A compiler is also needed to complete the program.
The language of 0s and 1s is called binary which is internally used by the computer system for performing different activities. The other levels of languages such as high level languages, assembly language are internally converted into binary language for the processing by the computers.
Assembly language code is the lowest-level form of programming before Machine code (binary), and each command in Assembler code directly references binary commands which tell the CPU what to do.
Assembly language is a low level language that uses mnemonics to represent each operation. Instead of using pure binary, like machine language does, these mnemonics allow for greater readibility and ease of understanding that binary does not. Additionally, an assembly language will have a set of data definitions that dictates where and how variables and their assigned data are stored.
Most assemblers support binary, decimal, hexadecimal and octal notations.
Suppose we give a 8-bit instruction ADD B to the microprocessor then this instruction is not at all understood by microprocessor as it only accepts binary inputs so first of all it stores the instruction in the INSTRUCTION REGISTOR then it decodes this instruction ADD B to its suitable binary code 80H in the INSTRUCTION DECODER.. after converting to 80H then the microprocessor understands that .. yes i have to add the content of the resistor B with that of A(accumulator) and store the result in the accumulator A this is a small example how microprocessor operates facing the instructions
"The x86 architecture first appeared as the Intel 8086 CPU released in 1978, a fully 16-bit design based on the earlier Intel 8085. Although not binary compatible, it was designed to allow assembly language programs written for the 8085 to be mechanically translated into the equivalent 8086 assembly. " Here's the entire Article: http://en.wikipedia.org/wiki/X86
Binary is made up of 0's and 1's. Binary can also be called Machine Code. Binary is the 'language' that the computer understands.