Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

EECE237Fall 2017 Homework 1 Assignment (due on 924/17) The task is to write an a

ID: 3888234 • Letter: E

Question


EECE237Fall 2017 Homework 1 Assignment (due on 924/17) The task is to write an assembly program to search the data stored in the memory locations starting from 0x20001000 to 0x2000101C (total 8 data) for the smallest number and store it to the memory location 0x20002000 1. Assume that the data are stored in the memory at the beginning Do not Resign any specific values to them. The program should be general enough to work with any data in the memory in any order 2. Note that a memory address increments by 4, not by l. 3. Use the for-loop style iteration to scan all memory data in the rangse. 4. Use R0 to store the smallest number. Use Rl to count the number of iteration. S. Deliverables Create a s file in uVision and build the target. Debug your program until you get 0 error. Write the class and section number, your name and Homework number at the very top in comments. Then submit your 's file to BBlearner. You can change your submission up to 5 times. Due time is the midnight of February 28 (Sun). * Hint 1. It, le. gt, ge conditions treat numbers signed. For unsigned numbers. use ls or hi. (piS8 Textbook) Use the post-offset indirect addressing to fetch data in the memory baseaddr index increment equ 4 equ 0x2000 1000 ldr 2.-baseaddr ldr 14.fr2]. #index-increment -fetch the data and increment r2 address compare 0 and ni blt moveonif 0 is less than 4, move on. If not. replace move on sub r1, r1,#1 decrement the counter by ons End

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