In: Computer Science
Here is the working code :
bits 32
global start
extern exit,printf, scanf ; it tells that exit exists even if we
won't be defining it
import exit msvcrt.dll ; exit function is defined in
msvcrt.dll
import printf msvcrt.dll ; contains important C-runtime specific
functions (exit, printf)
import scanf msvcrt.dll ; Data Declaration
segment data use32 class=data public
format_scanf db "%d", 0
format_printf1 db "Enter scores for both Raw and Total Score",
0x0d, 0x0a, 0
format_printf2 db "The result is = %d", 0x0d, 0x0a, 0
score1 dd 0
score2 dd 0
res dd 0
segment code use32 class=code public
start:
push dword format_printf1
call [printf]
add esp, 4*1
push score1
push dword format_scanf
call [scanf]
add esp, 4*2
push score2
push dword format_scanf
call [scanf]
add esp, 4*2
MOV EAX, [score1] ; we have the raw score
MOV EBX, [score2] ; we have the total score
MOV EDX, 0 ; Arithmetic operations start from here
MOV ECX, 50
MUL EBX ; start multiplication by 50, result store in EDX:EAX
DIV ECX ; EDX:EAX is divided by ECX (whose value is 50) and
quotient will be in EAX, and the remainder in EDX
ADD EAX, 50
MOV [res], EAX
push dword [res]
push dword format_printf2
call [printf]
add esp, 4*2
; exit(0)
push dword 0
call [exit]