Q2. Write a program in assembly language that calculatesthe sum of first five od
ID: 3610229 • Letter: Q
Question
Q2. Write a program in assembly language that calculatesthe sum of first five odd numbers (1, 3, 5, 7, 9) and stores theresult in AX register.You can do it with the help of loop(initialize AX register with value 0 and BX with value 1, and thenon each iteration of loop add BX into AX and add value 2 in BX).Youare NOT allowed to define the data (like num1: dw1, 3, 5, 7, 9)You have to submit the assembly language code forthis program and screen-shot of this program loaded in AFD debuggerin which the AX register contains the result.
Explanation / Answer
Solution
Effective Address = bx+ 30
= 0010 + 001E
= 002E
Effective Address = bx+ 20
= 0010 + 0014
= 0024
Effective Address =[bx + label]
= 0010 + 0124
= 0134
Effective Address =label + bx
= 0124 + 0010
= 0134
Effective Address = bx+ si
= 0010 + 00F1
= 00101
Effective Address = si+ 15
= 00F1 + 000F
= 0100
Solution
Ø Assembly language code:
[org 0x0100]
mov ax,0
mov bx,1
mov cx,5
l1:
add ax,bx
add bx,2
sub cx,1
jnz l1
mov ax, 0x4c00 ; terminate program
int 0x21
Ø Sample Screen-shot displaying result in AXregister (On AFD window
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.