Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sencagri/da4cf33d81bcc78406e27d974a5430a0 to your computer and use it in GitHub Desktop.
Save sencagri/da4cf33d81bcc78406e27d974a5430a0 to your computer and use it in GitHub Desktop.
test2
; Initially PC is set to 100
; Data section is right after the code section
.text 100
.global _main
_main:
ADD R1, R0, #10 ; init i
LDR R1, [R0, VAR_i] ; store i
ADDI R20, R0, #2
FOR_0:
LDR R1, [R0, VAR_i]
LT R1, END_FOR_0 ; i >= 0?
LSL R10, R1, R20 ; get correct word boundary
LDR R3, [R10,A] ; read A[i]
LDR R4, [R10,B] ; read B[i]
LDR R5, [R0, C] ; read C
LT R3, ELSE_0 ; A[i] >= 0 ?
SUB R6, R4, R5 ; B[i] - C
B TAIL_0
ELSE_0:
ADD R6, R4, R5 ; B[i] + C
TAIL_0:
STR R6, [R10,A] ; rewrite A[i]
ADDI R1, R1, #-1 ; i--
STR R1, [R0,VAR_i]
B FOR_0
END_FOR_0:
BREAK
A:
.word -1, -2, -3, 1, 2, 3, 0, 0, 5, -5, 6
B:
.word 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
C:
; let C be 1
.word 1
VAR_i:
; for var i
.word 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment