Need help wrinting the assembly code. The task is to write an assembly program t
ID: 3888817 • Letter: N
Question
Need help wrinting the assembly code.
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 1 ocation 0x20002000 Assume that the data are stored in the memory at the beginning. Do not assign any specific values to them. The program should be general enough to work with any data in the m Note that a memory address increments by 4, not by 1 Use the for-loop style iteration to scan all memory data in the range Use R0 to store the smallest number Use R1 to count the number of iteration. 1. emory n any order 2. 3. 4. 5. Deliverables Create a-s file Hint 1. lt, le, gt, ge conditions treat numbers signed. For unsigned numbers, use ls or hi. (p158 Textbook) 2. Use the post-offset indirect addressing to fetch data in the memory baseaddr index_increment equ 0x20001000 equ ldr r4, [r2]. #index increment fetch the data and increment r2 address cmp r0, r4 blmove onif r0 is less than r4, move on. If not, replace mov r0, r4 compare r0 and r4 move on sub r1,r1, #1 decrement the counter by one EndExplanation / Answer
int32_t i, temp=0, data[8]; //temp is equivalent to R0 register.
for (i=7; i>=0; i--) {if (temp>data[i]) temp=data[i];} //compare and keep the smaller one.
Use the post-offset indirect addressing to fetch data in the memory.
baseaddr equ 0x20001000
index_increment equ 4
. .
ldr r2, =baseaddr
ldr r4, [r2], #index_increment ;fetch the data and increment r2 address
cmp r0, r4 ;compare r0 and r4
blt move_on ;if r0 is less than r4, move on. If not, replace
mov r0, r4
move_on
sub r1, r1, #1 ;decrement the counter by one.
. .
End
for an example let us add 10 numbers and load
LDA XXXX // Some memory location say 8500
// Load the accumulator with the address of memory viz 8500
MOV D, A
// Move the accumulator value to the register D
MVI E, 09
// Load the E register with the counter 10 - 1
LXI B, XXXX + 1 // Next memory location from where we have done LDA - 8501
// Load immediate B C with the memory location
LDAX B
// Load Accumulator indirect A=[BC]
ADD D
//Add the content of the Accumulator to the Register D
MOV D, A
//Move the value in D to the Accumulator or register A
INX B
// Increment BC register pairs
DCR E
// Decrement the counter register
JNZ XXXX // LDAX B Location
// Jump on no zero
STA XXXX // Suitable memory location
// Store the output into a memory location
HLT
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.