Question

In: Computer Science

Write a subroutine that takes an int (.long) parameter and squares it. The parameter should be...

Write a subroutine that takes an int (.long) parameter and squares it. The parameter should be passed in on the stack. The answer should be returned in eax. The subroutine should not disturb any registers except eax, ecx, and edx. (Save any registers on the stack and restore them before exiting the subroutine.) Upon entry to the subroutine, push ebp, etc., to access the parameter.

Solutions

Expert Solution

[org 100h]
jmp start
var1:dw 4

square:
   pusha
   xor ax,ax
   xor bx,bx
   xor cx,cx
   xor dx,dx
   mov bp,sp
   mov bx,[bp + 14]
   mov cx,bx

   sq:
       add ax, bx
   loop sq

   popa
ret


start:
   xor cx,cx
   mov ax,[var1]
   push ax
   call square

mov ah, 4ch
int 21h

IF YOU HAVE ANY QUERY, KINDLY FEEL FREE TO ASK. AND LEAVE A THUMBS UP! THANKS!


Related Solutions

Write a java program calls the following methods: a. printStars(): Takes an int (n) as parameter...
Write a java program calls the following methods: a. printStars(): Takes an int (n) as parameter and prints n stars (*) using for loop. ex. 6 ******
C++ A void function named NextLeapYear() that takes an int reference parameter. If the parameter is...
C++ A void function named NextLeapYear() that takes an int reference parameter. If the parameter is positive, the function will assign it the next leap year after it; otherwise, the function will assign 4 to it.
Write a subroutine that will receive a char input value. This subroutine should then use a...
Write a subroutine that will receive a char input value. This subroutine should then use a switch statement to determine if the char is a vowel, consonant, digit, or other type of character. Write the subroutine only,
Write a subroutine that will receive a char input value. This subroutine should then use a...
Write a subroutine that will receive a char input value. This subroutine should then use a switch statement to determine if the char is a vowel, consonant, digit, or other type of character. Write the subroutine only, This is in C++
Write a function which takes one parameter int num, and prints out a countdown timer with...
Write a function which takes one parameter int num, and prints out a countdown timer with minutes and seconds separated by a colon (:). It should print out one line for each second elapsed and then pause one second before printing out the next line. A few things to note: - You can assume that calling the function usleep(1000000) makes the program pause for one second - It should count down from num minutes:zero seconds to zero minutes:zero seconds -...
Write a method that takes four strings as parameter. The first string should be a pokemon...
Write a method that takes four strings as parameter. The first string should be a pokemon name, the second a pokemon type, the third a pokemon name, and the fourth a pokemon type. The method should print out which pokemon has the advantage over the other based on their type. In this case you can use fire, water, and leaf. Example outputs should be like: Example: Pokemon X (Water) has the advantage over Pokemon Y (fire) Pokemon X (Fire) has...
Write a C function hwkOneA, that takes a long int x as well as two integers...
Write a C function hwkOneA, that takes a long int x as well as two integers n and m as arguments, and returns a long int. Here is the function declaration: long int hwkOneA (long int x, int n, int m); The function should swap nibble n and m of a long int x (64-bit integer). A nibble is a four-bit aggregation. For this problem, the index of the most significant nibble is 0, and the index of the least...
Implement a method that meets the following requirements: (a) Takes as parameter 1) an int array...
Implement a method that meets the following requirements: (a) Takes as parameter 1) an int array A 2) an int number x to search for (b) determines whether x exists in A, and prints a message indicating the result (c) has the best worst case Big Oh complexity you can manage, using only your own thinking and the materials (the worst case growth rate for the number of items searched should be as low as possible, given that A contains...
Multiples(): Takes an int (n) as parameter and prints first 10 multiples n in a single...
Multiples(): Takes an int (n) as parameter and prints first 10 multiples n in a single line using for loop. Code in Java Ex output: 5 5,10,15,20,25,30,35,40,45,50
C Write a function int sort(int** arr, int n) that takes as input an array of...
C Write a function int sort(int** arr, int n) that takes as input an array of int pointers, multiplies the ints the pointers point to by -1, and then sorts the array such that the values pointed to by the pointers are in decreasing order. For example, if the array is size 10 the pointer at index 0 will point to the largest value after multiplying by -1 and the pointer at index 9 will point to the smallest value...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT