The task is to write an assembly program to search the data stored in the memory
ID: 2085885 • Letter: T
Question
Explanation / Answer
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. An equivalent C program would look like
//This C program.
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
// Stop the program
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.