;------------------------------------------------------------------
; section 1: Targeted arithmetic instructions are of mainly four type
; 1- Addition
; 2- Subtraction
; 3- Multiplication
; 4- Comparision
;---------------------------------------------------------------------
TTL transfer
AREA Myprog, CODE, READONLY
ENTRY
EXPORT main
main
;Initialize values into R1, and R2
LDR R1,=0xFA
LDR R2,=0x15
;part 1 Addition operations
;Three operand arithmetic instructions
ADD R2,R1,R2 ;ADDS <Rd>, <Rn>, <Rm>
;Rd = Rn + Rm, APSR update
ADDS R3,R1,#0x07 ;ADDS <Rd>, <Rn>, #immed3
;Rd = Rn + ZeroExtend(#immed3), APSR update
ADDS R3,#0xFF ;ADDS <Rd>, #immed8
;Rd = Rd + ZeroExtend(#immed8), APSR update
ADD R4,R2 ;ADD <Rd>, <Rm>
;Rd = Rd + Rm
;Arithmetic operations with SP
ADD R3, SP, R3 ;ADD <Rd>, SP, <Rd>
;Rd = Rd + SP
ADD SP, R2 ;ADD SP, <Rm>
;SP = SP + Rm
ADD R2, SP, #0x04 ;ADD <Rd>, SP, #immed8
;Rd = SP + ZeroExtend (#immed8)
ADD SP, SP, #0x08 ;ADD SP, SP, #immed7
;SP = SP + ZeroExtend(#immed7)
;Arithmetic operations with PC
ADD R2, PC, #0x04 ;ADD <Rd>, PC, #immed8
;Rd = PC[31:0] + ZeroExtend(#immed8 << 2).
;Arithmetic operations with carry
ADCS R3, R2 ;ADCS <Rd>, <Rm>
;Rd = Rd + Rm + Carry.
;Part 2 Subtraction oprtations
;Three operand arithmatic instructions
SUBS R5, R1, R2 ;SUBS <Rd>, <Rn>, <Rm>
;Rd = Rn – Rm, APSR update
SUBS R5, R1, #0x07 ;SUBS <Rd>, <Rn>, #immed3
;Rd = Rn – ZeroExtend(#immed3), APSR update.
SUBS R5, #0x01 ; SUBS <Rd>, #immed8
;Rd = Rd – ZeroExtend(#immed8), APSR update.
;Arithmetic operations with SP
SUB SP, SP, #0x04 ;SUB SP, SP, #immed7
;SP = SP – ZeroExtend(#immed7)
;Arithmetic operations with carry
SBCS R6, R6, R2 ;SBCS <Rd>, <Rd>, <Rm>
;Rd = Rd – Rm – Borrow, APSR update
;Reverse Subtract
RSBS R7, R1, #0x00 ;RSBS <Rd>, <Rn>, #0
;Rd = 0 – Rm, APSR update
;part 3 multiplication
;Multiply
MULS R7, R1, R7 ;MULS <Rd>, <Rm>, <Rd>
;Rd = Rd * Rm, APSR.N and APSR.Z
;part 4 comparision
;Compare by subtraction but result is not stored
;Rm >Rn C =0, Z =0
;Rm <Rn C =1, Z =0
;Rm =Rn C =0, Z =1
CMP R1, R2 ;CMP <Rn>, <Rm>
;Calculate Rm – Rn, APSR update
CMP R2, #0x04 ;CMP <Rn>, #immed8
; ZeroExtended(#immed8) – Rd , APSR update
CMN R1, R2 ;CMN <Rn>, <Rm>
;Compare negative, Calculate NEG(Rm) – Rn , APSR update
done
SWI &11 ; Call system interrupt to end the program
END
No comments:
Post a Comment