In: Computer Science
Develop an x86 assembly language program that properly executes an "x to the y power" function:
int power(int x, int y)
Compute the integer value that is x to the y power
Do not concern yourself with the possibility of overflow
You may only use only a loop structure to compute the value
Remember that the return value must be placed in the EAX
register
Make sure that any registers (not EAX) used by this function are
placed back to their initial states prior to exiting
Allow an end user to test this function in the following manner:
Prompt the user to enter an integer value ("Enter a value for x:
")
Allow the user to input their value
Prompt the user to enter an integer value ("Enter a value for y:
")
Allow the user to input their value
Pass the user input value to the power() function Let the
function
do its work and return the correct value
Print out the result ("x to the y power is: ")
Here is your x86 assembly language program that properly executes an "x to the y power" function:
int power(int x, int y)
still if you have any doubt then feel free to ask in comment section, I am always happy to help you.
Please upvote.
I have included some comments, so you can understand what is going in code.
.MODEL SMALL
.DATA
greet db 13,10, "Simple Calculator: x to the y power. $"
msg1 db 13,10, 0AH,0DH,"Enter a value for x:: $"
m db 3,4 dup(?)
msg2 db 10,13, 0AH,0DH,"Enter a value for y:: $"
n db 3,4 dup(?)
total db 10,13, "x to the y power is: $"
.CODE
START:
mov ax, seg greet
mov ds, ax
mov dx, offset greet
mov ah, 09h ;Display message
int 21h
mov ax, seg msg1
mov ds, ax
mov dx, offset msg1
mov ah, 09h
int 21h ;Print a message
mov ah, 0ah
mov dx, offset m
int 21h ;Get 'x' value
n_POWER:
mov ax, seg msg2
mov ds, ax
mov dx, offset msg2
mov ah, 09h
int 21h ;Print a message
mov ah, 0ah
mov dx, offset n ;Get 'y' value
int 21h
mov ax, m
mov n, ax
mul ax, n
mov total, n
finish:
mov ah, 09h ;Display message
int 21h
mov ax,4c00h ;Return control to DOS
int 21h
end start
Please do not forget to hit that like or thumbs-up button, it really motivates me<3
Thank you!!
Have a nice day:)