-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path20_post_increment.asm
More file actions
25 lines (21 loc) · 960 Bytes
/
20_post_increment.asm
File metadata and controls
25 lines (21 loc) · 960 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
; Exercise 20: Post-Increment Addressing
; Level: 3 - Memory & Data Structures
;
; Goal: Read first 3 elements of an array using post-increment
; Array: [5, 10, 15, 20, 25] at 0x4000
;
; Instructions to use: LOADI, LOAD with [PAIR]+, HALT
; Expected result: R0=5, R1=10, R2=15, R6:R7=0x4003
;
; Hint: [PAIR]+ means: access memory at PAIR, then increment PAIR by 1
; Hint: Post-increment automatically advances to next array element
; Hint: This is the most efficient way to traverse arrays
section .code
loadi r6, 0x40 ; Load 0x40 into R6 (array base high)
loadi r7, 0x00 ; Load 0x00 into R7 (array base low)
load r0, [r6:r7]+ ; Load from [R6:R7]+ into R0 (reads 5, R6:R7 becomes 0x4001)
load r1, [r6:r7]+ ; Load from [R6:R7]+ into R1 (reads 10, R6:R7 becomes 0x4002)
load r2, [r6:r7]+ ; Load from [R6:R7]+ into R2 (reads 15, R6:R7 becomes 0x4003)
halt ; Halt
section .data
DB 5, 10, 15, 20, 25