Add comments to explain each line of the program and briefly explain the purpose
ID: 3864271 • Letter: A
Question
Add comments to explain each line of the program and briefly explain the purpose of the program. Determine the values of the symbols ‘main’, ‘bound’, ‘ipt’, and ‘loop’.
BR main
bound: .EQUATE 10
ipt: .EQUATE 0
main: SUBSP 2, i
DECI ipt, s
loop: LDWA ipt, s
CPWA bound, i
BRGE endloop
ADDA 1, i
STWA ipt, s
DECO ipt, s
LDBA ' ', i
STBA charOut, d
BR loop
endloop: ADDSP 2, i
STOP
.END
Explanation / Answer
This assembly program just print the number from 0 to 10, separated by a space ‘ ‘.
Here is the equivalent C code
#include <stdio.h>
int bound =10 ;
int ipt;
int main(){
scanf(“%d”, &ipt);
while(ipt>=bound){
pit = ipt+1 ;
printf(“%d ”, ipt);
}
return 0;
}
BR main //unconditional branching instruction
bound: .EQUATE 10 //global variable #2d
ipt: .EQUATE 0 //global variable #2d
main: SUBSP 2, i //push #bound in stack
DECI ipt, s // scanf(“%d”, &ipt)
loop: LDWA ipt, s //while (ipt>=bound) uses CPWA and BRGE for comparison mentioned in next two command
CPWA bound, i
BRGE endloop // Branch if ipt greater then or equal to bound
ADDA 1, i //add one to ipt
STWA ipt, s //store in ipt
DECO ipt, s // printf(“%d ”, ipt); including next two command
LDBA ' ', i
STBA charOut, d // print space (‘ ‘)after ipt
BR loop
endloop: ADDSP 2, i // pop #bound stack storage
STOP //Stop Execution
.END //The Sentinel for assembler
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.