EECE237Fall 2017 Homework 1 Assignment (due on 924/17) The task is to write an a
ID: 3888234 • Letter: E
Question
Explanation / Answer
DATA SEGMENT
baseaddr equ 0x20001000
step equ 4 ; Memory address increments by 4
DATA ENDS
CODE SEGMENT
ldr r0, #0 ; initialize r0 with 0
ldr r1, #0 ; initialize r1 with 0
ldr r2, =baseaddr ; initialize r2 with base address
MIN:
ldr r4,[r2], #step ; load r2 into r4, increment r2 to next data and work on r4 subsequently
cmp r0,r4 ; comapare if r0 & r4
bgt GT ; if r0>r4, jump GT to replace r0 by r4 [signed gt is used since data stored could be both positive or negative]
GT:
mov r0,r4 ; move r4 to r0
cmp r4, #0x2000101C ; compare address in r4 to #0x2000101C
bls MIN ; in r4 is less than or equal to #0x2000101C than iterate otherwise exit the loop (data is stored only till 0x2000101C) [unsigned lt is used since addresses would be always positive]
]
clr r2 ; clear register r2
clr r4 ; clear register r4
ldr r2, =baseaddr
MAX:
ldr r4,[r2], #step ; load r2 into r4, increment r2 to next data and work on r4 subsequently
cmp r1,r4 ; comapare if r1 & r4
blt LT ; if r1<r4, jump LT to replace r1 by r4[signed lt is used since data stored could be both positive or negative]
LT:
mov r1,r4 ; move r4 to r1
cmp r4, #0x2000101C ; compare address in r4 to #0x2000101C
bls MAX ; in r4 is less than or equal to #0x2000101C than iterate otherwise exit the loop (data is stored only till 0x2000101C)
CODE ENDS
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.