Introduction to Assembly Language Programming
Registers:
Register are used to store information temporarily, while the information could be
- a byte of data to be processed, or
- an address pointing to the data to be fetched
The 8 bits of a register are shown from MSB D7 to the LSB D0
MOV destination, soruce
purpose of this command copy source to destination.
symbol "#" shows that it is value (number)
Example:
MOV A,#55H ;load value 55H into reg. A
;NOTE: Method use to transfer value is known as
;Direct Addressing mode
MOV R0,A ;copy contents of A into R0
;(now A=R0=55H)
;NOTE: Method use to transfer value is known as
;Register Addressing mode
MOV R1,A ;copy contents of A into R1
;(now A=R0=R1=55H)
MOV R2,A ;copy contents of A into R2
;(now A=R0=R1=R2=55H)
MOV R3,#95H ;load value 95H into R3
;(now R3=95H)
MOV A,R3 ;copy contents of R3 into A
;now A=R3=95H
important points
- MOV A, #23H
- if you forgot to add symbol "#" then it will consider it as location. With this symbol it will consider it as value.
- MOV R5, #0F9H
- Add an extra 0 before HEX number A to F to indicate that it isis a hex number and not a letter as done in example; MOV R5, #0F9H
- If values 0 to F moved into an 8-bit register, the rest of the bits are assumed all zeros
- “MOV A, #5”, the result will be A=05; i.e., A= 00000101 in binary
- Moving a value that is too large into a register will cause an error
- MOV A, #7F2H ; ILLEGAL: 7F2H>(FFH) 8 bits
ADD command
ADD A, source
The ADD instruction tells the CPU to add the source byte to accumulator register A and put the result in register A
- Source operand can be either a register or immediate data, but the destination must always be register A
- Remember: “ADD R4, A” and “ADD R2, #12H” are invalid since A must be the destination of any arithmetic operation
Example:
MOV A, #25H ;load 25H into A
MOV R2, #34H ;load 34H into R2
ADD A, R2 ;add R2 to Accumulator
;(A = A + R2)
There are always many ways to write the same program, depending on the registers used
MOV A, #25H ;load one operand
;into A (A=25H)
ADD A, #34H ;add the second
;operand 34H to A
0 comments:
Post a Comment