Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can someone help me complete this code? Implement the following C program in MAS

ID: 3798825 • Letter: C

Question

Can someone help me complete this code?

Implement the following C program in MASM. Be sure to use proper spacing on all output. If necessary, first key in the C program and then implement the MASM program to insure the MASM program works identically to the C program:

#include
int main(){
int num1, num2;
printf(" %s","Enter a value for num1: ");
scanf("%d",&num1);
printf(" %s","Enter a value for num2: ");
scanf("%d",&num2);
printf(" %s ","num1 num2");
printf("%s%d%s%d "," ",num1," ",num2);
return 0;
}

Heres what i did:

INCLUDELIB msvcrtd
INCLUDELIB legacy_stdio_definitions
INCLUDELIB ucrt

; Normal directives
.386
.model flat,vC
.stack 100h


; Prototypes
printf PROTO argl:Ptr Byte, printlist:VARARG
exit PROTO errorCode:DWORD
scanf PROTO argl:Ptr Byte, printlist:VARARG

; Data segment
.data

   ; Input format string
       in1fmt byte "%d", 0

   ; 32-bit signed integer
       num1 sdword ?
       num2 sdword ?

   ; Format string for printf
       msg0fmt byte "%s", 0
       msg1fmt byte 0Ah, "%s%d",0Ah,0Ah,0
       msg2fmt byte "%s%d%s%d",0Ah,0Ah,0
      

       entry1 byte "Enter a value: " , 0
       entry2 byte "Enter a value: " , 0
       str1 byte " num1 num2" , 0
       space byte " " , 0
.code

INVOKE printf, ADDR msg0fmt, ADDR entry1

INVOKE scanf, ADDR msg0fmt, ADDR num1

INVOKE printf, ADDR msg0fmt, ADDR entry2

INVOKE scanf, ADDR msg0fmt, ADDR num2

Explanation / Answer

extern printf

extern scanf

section .data

num1 : dd 0

num2 : dd 0

str1 : db "Enter a value for num1:",10,0

str2 : db "%s",0

str3 : db "Enter a value for num2:",10

str4 : db "num1 num2",10,10,0

str5 : db "%d",32,32,32,"%d",10

section .text

push dword str1

call printf

ádd esp,4

push dword str2

push dword num1

call scanf

add esp,8

push dword str3

call printf

ádd esp,4

push dword str2

push dword num2

call scanf

add esp,8

push dword str4

call printf

add esp,4

push dword str5

push dword [num1]

push dword [num2]

call printf

add esp,12

mov eax,0

ret

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote