Question & Answer: please write the following Y86 assembley instructions for the following C code. Please write in text so I can copy and paste……

please write the following Y86 assembley instructions for the following C code. Please write in text so I can copy and paste.
/*
 * C program to find the GCD and LCM of two integers using Euclids' algorithm
 */
#include <stdio.h>
 
void main()
{
    int num1, num2, gcd, lcm, remainder, numerator, denominator;
 
    printf("Enter two numbersn");
    scanf("%d %d", &num1, &num2);
    if (num1 > num2)
    {
        numerator = num1;
        denominator = num2;
    }
    else
    {
        numerator = num2;
        denominator = num1;
    }
    remainder = numerator % denominator;
    while (remainder != 0)
    {
        numerator   = denominator;
        denominator = remainder;
        remainder   = numerator % denominator;
    }
    gcd = denominator;
    lcm = num1 * num2 / gcd;
    printf("GCD of %d and %d = %dn", num1, num2, gcd);
    printf("LCM of %d and %d = %dn", num1, num2, lcm);
}

Expert Answer

 

Source code assembly language:
%include “macros.s”
.DATA
num_lbl: DB “> Numbers (2): “, 0
gcd_lbl: DB “*** GCD: “, 0
lcm_lbl: DB “*** LCM: “, 0
num1: DD 0
num2: DD 0
num1_cpy: DD 0
num2_cpy: DD 0
gcd: DD 0
lcm: DD 0
.CODE
.STARTUP
xor EAX, EAX
xor EBX, EBX
xor ECX, ECX
xor EDX, EDX
xor EDI, EDI
xor ESI, ESI
main:
nwln
nwln
PutStr num_lbl
nwln
nwln
GetLInt [num1]
GetLInt [num2]
mov EAX, [num1]
mov [num1_cpy], EAX
mov EBX, [num2]
mov [num2_cpy], EBX
call calc_euclidean
call calc_lcm
nwln
PutStr gcd_lbl
PutLInt [gcd]
nwln
PutStr lcm_lbl
PutLInt [lcm]
nwln
.EXIT
calc_euclidean:
mov EAX, [num2]
cmp EAX, 0
jne chk_swap
mov EAX, [num1]
mov [gcd], EAX
ret
calc_lcm:
mov EAX, [num1_cpy]
mov EDX, [num2_cpy]
mul EDX
mov EDI, EAX
xor ebx,ebx
mov bx,[gcd]
xor edx,edx
div ebx
mov [lcm],eax
ret
chk_swap:
mov EAX, [num1]
mov EBX, [num2]
cmp EAX, EBX
jl swap
after_check:
jmp loop
swap:
mov EAX, [num1]
mov EBX, [num2]
; temp
mov ECX, [num2]
; num2 = num1
; num1 = temp
mov EBX, EAX
mov EAX, ECX
mov [num1], EAX
mov [num2], EBX
jmp after_check
loop:
mov EDX, [num1]
shr EDX, 16
mov EAX, [num1]
mov BX, [num2]
div BX
mov EDI, [num1]
mov ESI, [num2]
mov EDI, ESI
mov [num1], EDI
mov [num2], EDX
jmp calc_euclidean

Don't use plagiarized sources. Get Your Custom Essay on
Question & Answer: please write the following Y86 assembley instructions for the following C code. Please write in text so I can copy and paste……
GET AN ESSAY WRITTEN FOR YOU FROM AS LOW AS $13/PAGE
Order Essay

Still stressed from student homework?
Get quality assistance from academic writers!