The following program takes a user-inputted integer and adds 155, shifts it to the right twice, and prints the output after the addition, then after the shift. It is written in fasm x86 assembly and uses the stdcall convention:
format PE Console
entry main
include 'macro/import32.inc'
; Read-Only data
section '.rdata' data readable
msg db 'Enter a number and we will do some math to it: ', 0
msg2 db 13,10, 'The final result is: %d', 0, 13, 10
p db 'pause>nul', 0
msg3 db 13, 10, '%d + 155 is %d', 0
msg4 db 'You entered: %d', 0
section '.data' data readable writeable
frmspec db '%d'
number dd 0
section '.code' code readable executable
main:
push ebp
mov ebp, esp
; no local vars needed
push msg
call [printf]
sub esp, 4 ; clean stack
push number
push frmspec
call [scanf]
sub esp, 8 ; clean stack
push [number]
push msg4
call [printf]
sub esp, 8 ; clean stack
mov eax, [number]
add eax, 155
push eax
push [number]
push msg3
call [printf]
pop ecx
pop eax
pop ecx
shr eax, 2
mov dword [number], eax
push [number]
push msg2
call [printf]
sub esp, 8
mov esp, ebp
pop ebp
push p
call [system]
sub esp, 4
push 0
call [exit]
;imports
section '.idata' import data readable
library msvcrt, 'msvcrt.dll'
import msvcrt, \
printf, 'printf', \
system, 'system', \
scanf, 'scanf', \
exit, 'exit'