UNIVERSITY OF THE PUNJAB
Third Semester 2016
Examination: B.S. 4 Years Programme
Paper: Computer Organization and Assembly Language
Course Code: IT-203 / 21402
Question # 4:
Write an assembly language program that reads two numbers from keyboard 'n' and 'p' calculates the n raise to power p, i.e. n^p
Solution:
INCLUDE Irvine32.inc
.data
msg BYTE "Enter n : ",0
msg2 BYTE "Enter p : ",0
result BYTE "n raise to power p is : ",0
n DWORD ?
p DWORD ?
res DWORD ?
.code
main PROC
mov edx, offset msg
call WriteString
call ReadInt
mov n, eax
mov edx, offset msg2
call WriteString
call ReadInt
mov p,eax
mov ecx, p
mov eax, 1
L1:
mul n
loop L1
mov edx, offset result
call WriteString
call WriteDec
quit:
call crlf
call WaitMsg
exit
main ENDP
END main
.data
msg BYTE "Enter n : ",0
msg2 BYTE "Enter p : ",0
result BYTE "n raise to power p is : ",0
n DWORD ?
p DWORD ?
res DWORD ?
.code
main PROC
mov edx, offset msg
call WriteString
call ReadInt
mov n, eax
mov edx, offset msg2
call WriteString
call ReadInt
mov p,eax
mov ecx, p
mov eax, 1
L1:
mul n
loop L1
mov edx, offset result
call WriteString
call WriteDec
quit:
call crlf
call WaitMsg
exit
main ENDP
END main
Let me know in the comment section if you have any question.
Previous Post:
Program that reads a character from keyboard and displays next five and previous five characters.
Comments
Post a Comment