arm assembler - rigwit.co.uk · systems architecture arm assembler ... • does not work in the...
TRANSCRIPT
![Page 1: ARM Assembler - rigwit.co.uk · Systems Architecture ARM Assembler ... • Does not work in the ARMulator • An ARM word is 32-bits, so a Halfword is 16-bits ... Debug will place](https://reader034.vdocuments.us/reader034/viewer/2022050202/5f55cdcd17056074c272ac57/html5/thumbnails/1.jpg)
Systems Architecture
ARM Assembler
Data Movement
Beginning Programs – p. 1/10
![Page 2: ARM Assembler - rigwit.co.uk · Systems Architecture ARM Assembler ... • Does not work in the ARMulator • An ARM word is 32-bits, so a Halfword is 16-bits ... Debug will place](https://reader034.vdocuments.us/reader034/viewer/2022050202/5f55cdcd17056074c272ac57/html5/thumbnails/2.jpg)
Memory Access
• Load Register from memoryLDR〈cc〉 Rd, 〈op2〉 〈cc〉: MAR ← 〈op2〉
〈cc〉: MBR ← M(MAR)〈cc〉: Rd ← MBR
• Store Register in memorySTR〈cc〉 Rs, 〈op2〉 〈cc〉: MAR ← 〈op2〉
〈cc〉: MBR ← Rs
〈cc〉: M(MAR) ← MBR
• Memory Reference must be 32-bit word alignedotherwise a Data Abort Exception will occuruse the ALIGN directive to force alignment
Beginning Programs – p. 2/10
![Page 3: ARM Assembler - rigwit.co.uk · Systems Architecture ARM Assembler ... • Does not work in the ARMulator • An ARM word is 32-bits, so a Halfword is 16-bits ... Debug will place](https://reader034.vdocuments.us/reader034/viewer/2022050202/5f55cdcd17056074c272ac57/html5/thumbnails/3.jpg)
Load / Store Byte
• Load Register with unsigned Byte from memoryLDR〈cc〉B Rd, 〈op2〉 〈cc〉: MAR ← 〈op2〉
〈cc〉: MBR ← M(MAR)〈cc〉: Rd(7:0) ← MBR〈cc〉: Rd(31:8) ← 0
• Load Register with Signed Byte from memoryLDR〈cc〉SB Rd, 〈op2〉 〈cc〉: MAR ← 〈op2〉
〈cc〉: MBR ← M(MAR)〈cc〉: Rd(7:0) ← MBR〈cc〉: Rd(31:8) ← Rd(7)
• Store Register in a Byte of memorySTR〈cc〉B Rs, 〈op2〉 〈cc〉: MAR ← 〈op2〉
〈cc〉: MBR ← Rs
〈cc〉: M(MAR) ← Rs(7:0)Beginning Programs – p. 3/10
![Page 4: ARM Assembler - rigwit.co.uk · Systems Architecture ARM Assembler ... • Does not work in the ARMulator • An ARM word is 32-bits, so a Halfword is 16-bits ... Debug will place](https://reader034.vdocuments.us/reader034/viewer/2022050202/5f55cdcd17056074c272ac57/html5/thumbnails/4.jpg)
Load / Store Halfword• Does not work in the ARMulator• An ARM word is 32-bits, so a Halfword is 16-bits• Memory Reference must be Halfword aligned• Load Register with unsigned Halfword from memory
LDR〈cc〉H Rd, 〈op2〉 〈cc〉: MAR ← 〈op2〉〈cc〉: MBR ← M(MAR)〈cc〉: Rd(15:0) ← MBR〈cc〉: Rd(31:16)← 0
• Load Register with Signed Halfword from memoryLDR〈cc〉SH Rd, 〈op2〉 〈cc〉: MAR ← 〈op2〉
〈cc〉: MBR ← M(MAR)〈cc〉: Rd(15:0) ← MBR〈cc〉: Rd(31:16)← Rd(15)
• Store Register in a Halfword of memorySTR〈cc〉H Rs, 〈op2〉 〈cc〉: MAR ← 〈op2〉
〈cc〉: MBR ← Rs
〈cc〉: M(MAR) ← MBR(15:0)Beginning Programs – p. 4/10
![Page 5: ARM Assembler - rigwit.co.uk · Systems Architecture ARM Assembler ... • Does not work in the ARMulator • An ARM word is 32-bits, so a Halfword is 16-bits ... Debug will place](https://reader034.vdocuments.us/reader034/viewer/2022050202/5f55cdcd17056074c272ac57/html5/thumbnails/5.jpg)
Program: move16.s
1. ; 16bit data transfer2.3. TTL move16 – 16-bit data transfer4. AREA Program, CODE, READONLY5. ENTRY6.7. Main8. LDRB R1, Value ; Load value9. STR R1, Result ; Sore it again
10. SWI &11 ; exit()11.12. Value DCW &C123 ; Source value to be moved13. ALIGN ; Alling next word14. Result DCW 0 ; Reserve space for result15.16. END
Beginning Programs – p. 5/10
![Page 6: ARM Assembler - rigwit.co.uk · Systems Architecture ARM Assembler ... • Does not work in the ARMulator • An ARM word is 32-bits, so a Halfword is 16-bits ... Debug will place](https://reader034.vdocuments.us/reader034/viewer/2022050202/5f55cdcd17056074c272ac57/html5/thumbnails/6.jpg)
Program: move16.s
1. ; 16bit data transfer2.3. TTL move16 – 16-bit data transfer4. AREA Program, CODE, READONLY5. ENTRY6.7. Main8. LDRB R1, Value ; Load value9. STR R1, Result ; Sore it again
10. SWI &11 ; exit()11.12. Value DCW &C123 ; Source value to be moved13. ALIGN ; Alling next word14. Result DCW 0 ; Reserve space for result15.16. END
TTL Define Program Title
Beginning Programs – p. 5/10
![Page 7: ARM Assembler - rigwit.co.uk · Systems Architecture ARM Assembler ... • Does not work in the ARMulator • An ARM word is 32-bits, so a Halfword is 16-bits ... Debug will place](https://reader034.vdocuments.us/reader034/viewer/2022050202/5f55cdcd17056074c272ac57/html5/thumbnails/7.jpg)
Program: move16.s
1. ; 16bit data transfer2.3. TTL move16 – 16-bit data transfer4. AREA Program, CODE, READONLY5. ENTRY6.7. Main8. LDRB R1, Value ; Load value9. STR R1, Result ; Sore it again
10. SWI &11 ; exit()11.12. Value DCW &C123 ; Source value to be moved13. ALIGN ; Alling next word14. Result DCW 0 ; Reserve space for result15.16. END
AREA Label Program Area
Code or Data space; Read Only or Read / WriteBeginning Programs – p. 5/10
![Page 8: ARM Assembler - rigwit.co.uk · Systems Architecture ARM Assembler ... • Does not work in the ARMulator • An ARM word is 32-bits, so a Halfword is 16-bits ... Debug will place](https://reader034.vdocuments.us/reader034/viewer/2022050202/5f55cdcd17056074c272ac57/html5/thumbnails/8.jpg)
Program: move16.s
1. ; 16bit data transfer2.3. TTL move16 – 16-bit data transfer4. AREA Program, CODE, READONLY5. ENTRY6.7. Main8. LDRB R1, Value ; Load value9. STR R1, Result ; Sore it again
10. SWI &11 ; exit()11.12. Value DCW &C123 ; Source value to be moved13. ALIGN ; Alling next word14. Result DCW 0 ; Reserve space for result15.16. END
ENTRY Define Program Entry Point
Beginning Programs – p. 5/10
![Page 9: ARM Assembler - rigwit.co.uk · Systems Architecture ARM Assembler ... • Does not work in the ARMulator • An ARM word is 32-bits, so a Halfword is 16-bits ... Debug will place](https://reader034.vdocuments.us/reader034/viewer/2022050202/5f55cdcd17056074c272ac57/html5/thumbnails/9.jpg)
Program: move16.s
1. ; 16bit data transfer2.3. TTL move16 – 16-bit data transfer4. AREA Program, CODE, READONLY5. ENTRY6.7. Main8. LDRB R1, Value ; Load value9. STR R1, Result ; Sore it again
10. SWI &11 ; exit()11.12. Value DCW &C123 ; Source value to be moved13. ALIGN ; Alling next word14. Result DCW 0 ; Reserve space for result15.16. END
Main Label the memory address
Debug will place breakpoint at MainBeginning Programs – p. 5/10
![Page 10: ARM Assembler - rigwit.co.uk · Systems Architecture ARM Assembler ... • Does not work in the ARMulator • An ARM word is 32-bits, so a Halfword is 16-bits ... Debug will place](https://reader034.vdocuments.us/reader034/viewer/2022050202/5f55cdcd17056074c272ac57/html5/thumbnails/10.jpg)
Program: move16.s
1. ; 16bit data transfer2.3. TTL move16 – 16-bit data transfer4. AREA Program, CODE, READONLY5. ENTRY6.7. Main8. LDRB R1, Value ; Load value9. STR R1, Result ; Sore it again
10. SWI &11 ; exit()11.12. Value DCW &C123 ; Source value to be moved13. ALIGN ; Alling next word14. Result DCW 0 ; Reserve space for result15.16. END
SWI Software Interrupt — Call the Operating System
exit()Beginning Programs – p. 5/10
![Page 11: ARM Assembler - rigwit.co.uk · Systems Architecture ARM Assembler ... • Does not work in the ARMulator • An ARM word is 32-bits, so a Halfword is 16-bits ... Debug will place](https://reader034.vdocuments.us/reader034/viewer/2022050202/5f55cdcd17056074c272ac57/html5/thumbnails/11.jpg)
Program: move16.s
1. ; 16bit data transfer2.3. TTL move16 – 16-bit data transfer4. AREA Program, CODE, READONLY5. ENTRY6.7. Main8. LDRB R1, Value ; Load value9. STR R1, Result ; Sore it again
10. SWI &11 ; exit()11.12. Value DCW &C123 ; Source value to be moved13. ALIGN ; Alling next word14. Result DCW 0 ; Reserve space for result15.16. END
& Define a Hexadecimal value
Beginning Programs – p. 5/10
![Page 12: ARM Assembler - rigwit.co.uk · Systems Architecture ARM Assembler ... • Does not work in the ARMulator • An ARM word is 32-bits, so a Halfword is 16-bits ... Debug will place](https://reader034.vdocuments.us/reader034/viewer/2022050202/5f55cdcd17056074c272ac57/html5/thumbnails/12.jpg)
Program: move16.s
1. ; 16bit data transfer2.3. TTL move16 – 16-bit data transfer4. AREA Program, CODE, READONLY5. ENTRY6.7. Main8. LDRB R1, Value ; Load value9. STR R1, Result ; Sore it again
10. SWI &11 ; exit()11.12. Value DCW &C123 ; Source value to be moved13. ALIGN ; Alling next word14. Result DCW 0 ; Reserve space for result15.16. END
DCW Define a 16-bit data value
Beginning Programs – p. 5/10
![Page 13: ARM Assembler - rigwit.co.uk · Systems Architecture ARM Assembler ... • Does not work in the ARMulator • An ARM word is 32-bits, so a Halfword is 16-bits ... Debug will place](https://reader034.vdocuments.us/reader034/viewer/2022050202/5f55cdcd17056074c272ac57/html5/thumbnails/13.jpg)
Program: move16.s
1. ; 16bit data transfer2.3. TTL move16 – 16-bit data transfer4. AREA Program, CODE, READONLY5. ENTRY6.7. Main8. LDRB R1, Value ; Load value9. STR R1, Result ; Sore it again
10. SWI &11 ; exit()11.12. Value DCW &C123 ; Source value to be moved13. ALIGN ; Alling next word14. Result DCW 0 ; Reserve space for result15.16. END
ALIGN Align data item on 32-bit word boundary
Beginning Programs – p. 5/10
![Page 14: ARM Assembler - rigwit.co.uk · Systems Architecture ARM Assembler ... • Does not work in the ARMulator • An ARM word is 32-bits, so a Halfword is 16-bits ... Debug will place](https://reader034.vdocuments.us/reader034/viewer/2022050202/5f55cdcd17056074c272ac57/html5/thumbnails/14.jpg)
Program: move16.s
1. ; 16bit data transfer2.3. TTL move16 – 16-bit data transfer4. AREA Program, CODE, READONLY5. ENTRY6.7. Main8. LDRB R1, Value ; Load value9. STR R1, Result ; Sore it again
10. SWI &11 ; exit()11.12. Value DCW &C123 ; Source value to be moved13. ALIGN ; Alling next word14. Result DCW 0 ; Reserve space for result15.16. END
END End of program source
Beginning Programs – p. 5/10
![Page 15: ARM Assembler - rigwit.co.uk · Systems Architecture ARM Assembler ... • Does not work in the ARMulator • An ARM word is 32-bits, so a Halfword is 16-bits ... Debug will place](https://reader034.vdocuments.us/reader034/viewer/2022050202/5f55cdcd17056074c272ac57/html5/thumbnails/15.jpg)
Program: move16.s
1. ; 16bit data transfer2.3. TTL move16 – 16-bit data transfer4. AREA Program, CODE, READONLY5. ENTRY6.7. Main8. LDRB R1, Value ; Load value9. STR R1, Result ; Sore it again
10. SWI &11 ; exit()11.12. Value DCW &C123 ; Source value to be moved13. ALIGN ; Alling next word14. Result DCW 0 ; Reserve space for result15.16. END
Bug Assembler can only find syntax errors
You have to find the logical errorsBeginning Programs – p. 5/10
![Page 16: ARM Assembler - rigwit.co.uk · Systems Architecture ARM Assembler ... • Does not work in the ARMulator • An ARM word is 32-bits, so a Halfword is 16-bits ... Debug will place](https://reader034.vdocuments.us/reader034/viewer/2022050202/5f55cdcd17056074c272ac57/html5/thumbnails/16.jpg)
Data Movement
• MOV Move DataMOVS Move Data and Set Zero and Negative flagsMOV〈cc〉 Move Data if 〈cc〉
• MOV〈cc〉〈S〉 Rd, 〈op1〉 〈cc〉: ALU ← 〈op1〉〈cc〉: Rd ← ALU
〈S〉〈cc〉: CPSR ← ALU(Flags)
• Move and Negate DataMVN〈cc〉〈S〉 Rd, 〈op1〉 〈cc〉: ALU ← 〈op1〉
〈cc〉: Rd ← ALU〈S〉〈cc〉: CPSR ← ALU(Flags)
• Rd is the destination (must be a register)• 〈op1〉 is the source
Beginning Programs – p. 6/10
![Page 17: ARM Assembler - rigwit.co.uk · Systems Architecture ARM Assembler ... • Does not work in the ARMulator • An ARM word is 32-bits, so a Halfword is 16-bits ... Debug will place](https://reader034.vdocuments.us/reader034/viewer/2022050202/5f55cdcd17056074c272ac57/html5/thumbnails/17.jpg)
Program: invert.s
1. ; Find the one’s compliment (inverse) of a number2.3. TTL invert.s – one’s complement4. AREA Program, CODE, READONLY5. ENTRY6.7. Main8. LDR R1, Value ; Load number to be processed9. MVN R1, R1 ; Invert (not) the value
10. STR R1, Result ; Store the result11. SWI &11 ; exit()12.13. Value DCD &C123 ; Value to be complemented14. Result DCD 0 ; Reserve space for result15.16. END
Beginning Programs – p. 7/10
![Page 18: ARM Assembler - rigwit.co.uk · Systems Architecture ARM Assembler ... • Does not work in the ARMulator • An ARM word is 32-bits, so a Halfword is 16-bits ... Debug will place](https://reader034.vdocuments.us/reader034/viewer/2022050202/5f55cdcd17056074c272ac57/html5/thumbnails/18.jpg)
Program: invert.s
1. ; Find the one’s compliment (inverse) of a number2.3. TTL invert.s – one’s complement4. AREA Program, CODE, READONLY5. ENTRY6.7. Main8. LDR R1, Value ; Load number to be processed9. MVN R1, R1 ; Invert (not) the value
10. STR R1, Result ; Store the result11. SWI &11 ; exit()12.13. Value DCD &C123 ; Value to be complemented14. Result DCD 0 ; Reserve space for result15.16. END
Labels Used to access memory directly
Beginning Programs – p. 7/10
![Page 19: ARM Assembler - rigwit.co.uk · Systems Architecture ARM Assembler ... • Does not work in the ARMulator • An ARM word is 32-bits, so a Halfword is 16-bits ... Debug will place](https://reader034.vdocuments.us/reader034/viewer/2022050202/5f55cdcd17056074c272ac57/html5/thumbnails/19.jpg)
Program: invert.s
1. ; Find the one’s compliment (inverse) of a number2.3. TTL invert.s – one’s complement4. AREA Program, CODE, READONLY5. ENTRY6.7. Main8. LDR R1, Value ; Load number to be processed9. MVN R1, R1 ; Invert (not) the value
10. STR R1, Result ; Store the result11. SWI &11 ; exit()12.13. Value DCD &C123 ; Value to be complemented14. Result DCD 0 ; Reserve space for result15.16. END
DCD Used to define (and initialise) memory values
No need for ALIGN as DCD defines 32-bit valuesBeginning Programs – p. 7/10
![Page 20: ARM Assembler - rigwit.co.uk · Systems Architecture ARM Assembler ... • Does not work in the ARMulator • An ARM word is 32-bits, so a Halfword is 16-bits ... Debug will place](https://reader034.vdocuments.us/reader034/viewer/2022050202/5f55cdcd17056074c272ac57/html5/thumbnails/20.jpg)
Program: invert.s
1. ; Find the one’s compliment (inverse) of a number2.3. TTL invert.s – one’s complement4. AREA Program, CODE, READONLY5. ENTRY6.7. Main8. LDR R1, Value ; Load number to be processed9. MVN R1, R1 ; Invert (not) the value
10. STR R1, Result ; Store the result11. SWI &11 ; exit()12.13. Value DCD &C123 ; Value to be complemented14. Result DCD 0 ; Reserve space for result15.16. END
MNV Move and Negate
Uses same register for Source1 and DestinationBeginning Programs – p. 7/10
![Page 21: ARM Assembler - rigwit.co.uk · Systems Architecture ARM Assembler ... • Does not work in the ARMulator • An ARM word is 32-bits, so a Halfword is 16-bits ... Debug will place](https://reader034.vdocuments.us/reader034/viewer/2022050202/5f55cdcd17056074c272ac57/html5/thumbnails/21.jpg)
Arithmetic
• AdditionADD〈cc〉〈S〉 Rd, Rn, 〈op1〉 〈cc〉: ALU ← Rn + 〈op1〉
〈cc〉: Rd ← ALU〈S〉〈cc〉: CPSR← ALU(Flags)
• SubtractionSUB〈cc〉〈S〉 Rd, Rn, 〈op1〉 〈cc〉: ALU ← Rn − 〈op1〉
〈cc〉: Rd ← ALU〈S〉〈cc〉: CPSR← ALU(Flags)
• MultiplicationMUL〈cc〉〈S〉 Rd, Rn, Rs 〈cc〉: ALU ← Rn × Rs
〈cc〉: Rd ← ALU〈S〉〈cc〉: CPSR← ALU(Flags)
Multiply two 16-bit values (Rn and Rs) producing a 32-bit result (Rd)
• DivisionThere is no division instruction
Beginning Programs – p. 8/10
![Page 22: ARM Assembler - rigwit.co.uk · Systems Architecture ARM Assembler ... • Does not work in the ARMulator • An ARM word is 32-bits, so a Halfword is 16-bits ... Debug will place](https://reader034.vdocuments.us/reader034/viewer/2022050202/5f55cdcd17056074c272ac57/html5/thumbnails/22.jpg)
Program: add2.s
1. ; Add two numbers and store the result. . .
7. Main8. LDR R0, =Value1 ; R0 = &Value19. LDR R1, [R0] ; R1 = *R0
10. ADD R0, R0, #0x4 ; R0++11. LDR R2, [R0] ; R2 = *R012. ADD R1, R1, R2 ; R1 = R1 + R213. LDR R0, =Result ; R0 = &Result14. STR R1, [R0] ; *R0 = R115. SWI &11 ; exit(0)16.17. Value1 DCD &37E3C12318. Value2 DCD &367402AA19. Result DCD 0
. . .
Beginning Programs – p. 9/10
![Page 23: ARM Assembler - rigwit.co.uk · Systems Architecture ARM Assembler ... • Does not work in the ARMulator • An ARM word is 32-bits, so a Halfword is 16-bits ... Debug will place](https://reader034.vdocuments.us/reader034/viewer/2022050202/5f55cdcd17056074c272ac57/html5/thumbnails/23.jpg)
Program: add2.s
1. ; Add two numbers and store the result. . .
7. Main8. LDR R0, =Value1 ; R0 = &Value19. LDR R1, [R0] ; R1 = *R0
10. ADD R0, R0, #0x4 ; R0++11. LDR R2, [R0] ; R2 = *R012. ADD R1, R1, R2 ; R1 = R1 + R213. LDR R0, =Result ; R0 = &Result14. STR R1, [R0] ; *R0 = R115. SWI &11 ; exit(0)16.17. Value1 DCD &37E3C12318. Value2 DCD &367402AA19. Result DCD 0
. . .
. . . Lines of no interest are ignored
Beginning Programs – p. 9/10
![Page 24: ARM Assembler - rigwit.co.uk · Systems Architecture ARM Assembler ... • Does not work in the ARMulator • An ARM word is 32-bits, so a Halfword is 16-bits ... Debug will place](https://reader034.vdocuments.us/reader034/viewer/2022050202/5f55cdcd17056074c272ac57/html5/thumbnails/24.jpg)
Program: add2.s
1. ; Add two numbers and store the result. . .
7. Main8. LDR R0, =Value1 ; R0 = &Value19. LDR R1, [R0] ; R1 = *R0
10. ADD R0, R0, #0x4 ; R0++11. LDR R2, [R0] ; R2 = *R012. ADD R1, R1, R2 ; R1 = R1 + R213. LDR R0, =Result ; R0 = &Result14. STR R1, [R0] ; *R0 = R115. SWI &11 ; exit(0)16.17. Value1 DCD &37E3C12318. Value2 DCD &367402AA19. Result DCD 0
. . .
ADD Same register for Source1 and Destination
Beginning Programs – p. 9/10
![Page 25: ARM Assembler - rigwit.co.uk · Systems Architecture ARM Assembler ... • Does not work in the ARMulator • An ARM word is 32-bits, so a Halfword is 16-bits ... Debug will place](https://reader034.vdocuments.us/reader034/viewer/2022050202/5f55cdcd17056074c272ac57/html5/thumbnails/25.jpg)
Program: add2.s
1. ; Add two numbers and store the result. . .
7. Main8. LDR R0, =Value1 ; R0 = &Value19. LDR R1, [R0] ; R1 = *R0
10. ADD R0, R0, #0x4 ; R0++11. LDR R2, [R0] ; R2 = *R012. ADD R1, R1, R2 ; R1 = R1 + R213. LDR R0, =Result ; R0 = &Result14. STR R1, [R0] ; *R0 = R115. SWI &11 ; exit(0)16.17. Value1 DCD &37E3C12318. Value2 DCD &367402AA19. Result DCD 0
. . .
=label Load address of label into R0
Beginning Programs – p. 9/10
![Page 26: ARM Assembler - rigwit.co.uk · Systems Architecture ARM Assembler ... • Does not work in the ARMulator • An ARM word is 32-bits, so a Halfword is 16-bits ... Debug will place](https://reader034.vdocuments.us/reader034/viewer/2022050202/5f55cdcd17056074c272ac57/html5/thumbnails/26.jpg)
Program: add2.s
1. ; Add two numbers and store the result. . .
7. Main8. LDR R0, =Value1 ; R0 = &Value19. LDR R1, [R0] ; R1 = *R0
10. ADD R0, R0, #0x4 ; R0++11. LDR R2, [R0] ; R2 = *R012. ADD R1, R1, R2 ; R1 = R1 + R213. LDR R0, =Result ; R0 = &Result14. STR R1, [R0] ; *R0 = R115. SWI &11 ; exit(0)16.17. Value1 DCD &37E3C12318. Value2 DCD &367402AA19. Result DCD 0
. . .
LDR Load data from memory pointed to by R0
Beginning Programs – p. 9/10
![Page 27: ARM Assembler - rigwit.co.uk · Systems Architecture ARM Assembler ... • Does not work in the ARMulator • An ARM word is 32-bits, so a Halfword is 16-bits ... Debug will place](https://reader034.vdocuments.us/reader034/viewer/2022050202/5f55cdcd17056074c272ac57/html5/thumbnails/27.jpg)
Program: add2.s
1. ; Add two numbers and store the result. . .
7. Main8. LDR R0, =Value1 ; R0 = &Value19. LDR R1, [R0] ; R1 = *R0
10. ADD R0, R0, #0x4 ; R0++11. LDR R2, [R0] ; R2 = *R012. ADD R1, R1, R2 ; R1 = R1 + R213. LDR R0, =Result ; R0 = &Result14. STR R1, [R0] ; *R0 = R115. SWI &11 ; exit(0)16.17. Value1 DCD &37E3C12318. Value2 DCD &367402AA19. Result DCD 0
. . .
ADD Increment pointer in R0 by a word (4 bytes)
Beginning Programs – p. 9/10
![Page 28: ARM Assembler - rigwit.co.uk · Systems Architecture ARM Assembler ... • Does not work in the ARMulator • An ARM word is 32-bits, so a Halfword is 16-bits ... Debug will place](https://reader034.vdocuments.us/reader034/viewer/2022050202/5f55cdcd17056074c272ac57/html5/thumbnails/28.jpg)
Program: add2.s
1. ; Add two numbers and store the result. . .
7. Main8. LDR R0, =Value1 ; R0 = &Value19. LDR R1, [R0] ; R1 = *R0
10. ADD R0, R0, #0x4 ; R0++11. LDR R2, [R0] ; R2 = *R012. ADD R1, R1, R2 ; R1 = R1 + R213. LDR R0, =Result ; R0 = &Result14. STR R1, [R0] ; *R0 = R115. SWI &11 ; exit(0)16.17. Value1 DCD &37E3C12318. Value2 DCD &367402AA19. Result DCD 0
. . .
ADD/LDR No need for ADD instructions if LDR uses post-index
addressing: [R0], #0x4 or *(R0++) in CBeginning Programs – p. 9/10
![Page 29: ARM Assembler - rigwit.co.uk · Systems Architecture ARM Assembler ... • Does not work in the ARMulator • An ARM word is 32-bits, so a Halfword is 16-bits ... Debug will place](https://reader034.vdocuments.us/reader034/viewer/2022050202/5f55cdcd17056074c272ac57/html5/thumbnails/29.jpg)
Program: add2.s
1. ; Add two numbers and store the result. . .
7. Main8. LDR R0, =Value1 ; R0 = &Value19. LDR R1, [R0] ; R1 = *R0
10. ADD R0, R0, #0x4 ; R0++11. LDR R2, [R0] ; R2 = *R012. ADD R1, R1, R2 ; R1 = R1 + R213. LDR R0, =Result ; R0 = &Result14. STR R1, [R0] ; *R0 = R115. SWI &11 ; exit(0)16.17. Value1 DCD &37E3C12318. Value2 DCD &367402AA19. Result DCD 0
. . .
STR Store data indirect (at memory pointed to by R0)
Beginning Programs – p. 9/10
![Page 30: ARM Assembler - rigwit.co.uk · Systems Architecture ARM Assembler ... • Does not work in the ARMulator • An ARM word is 32-bits, so a Halfword is 16-bits ... Debug will place](https://reader034.vdocuments.us/reader034/viewer/2022050202/5f55cdcd17056074c272ac57/html5/thumbnails/30.jpg)
Program: add2.s
1. ; Add two numbers and store the result. . .
7. Main8. LDR R0, =Value1 ; R0 = &Value19. LDR R1, [R0] ; R1 = *R0
10. ADD R0, R0, #0x4 ; R0++11. LDR R2, [R0] ; R2 = *R012. ADD R1, R1, R2 ; R1 = R1 + R213. LDR R0, =Result ; R0 = &Result14. STR R1, [R0] ; *R0 = R115. SWI &11 ; exit(0)16.17. Value1 DCD &37E3C12318. Value2 DCD &367402AA19. Result DCD 0
. . .
Comments These are bad comments
Comments should say why not whatBeginning Programs – p. 9/10
![Page 31: ARM Assembler - rigwit.co.uk · Systems Architecture ARM Assembler ... • Does not work in the ARMulator • An ARM word is 32-bits, so a Halfword is 16-bits ... Debug will place](https://reader034.vdocuments.us/reader034/viewer/2022050202/5f55cdcd17056074c272ac57/html5/thumbnails/31.jpg)
Program: shiftleft.s
1. ; Shift Left one bit2.3. TTL shiftleft.s4. AREA Program, CODE, READONLY5. ENTRY6.7. Main8. LDR R1, Value ; Load the value to be shifted9. MOV R1, R1, LSL #0x1 ; Shift Left one bit
10. STR R1, Result ; Store the result11. SWI &11 ; exit12.13. Value DCD &4242 ; Value to be shifted14. Result DCD 0 ; Space to store result15.16. END
LSL Logical Shift Left by 1 bit
Beginning Programs – p. 10/10