OneCompiler

Assembly language & C

#program author: Niyigena aime pacifique
.intel_syntax noprefix
#--------------------------------------------------------
#program that can calculate the user product
#depending on asking the user information product they buy
#---------------------------------------------------------
#---------------------------------------------------------
#start the section containing initialized data
#---------------------------------------------------------
.section .data
user_menu:
.string "\n---------------------------------------------\n[ONLINE PRODUCT AVAILAIBLE] \n---------------------------------------------\n[1] SWEET POTATOE \n[2] IRISH POTATOE \n[3] RICE \n[4] MAIZE FLOUR\n"
choose:
.string "\n ---------------------------------------------\n[ENTER PRODUCT No] ==>"
message:
.string "\nWELCOME TO ONLINE BUY\n---------------------------------------------\n"
price_sp:
.string "\n[SWEET POTATOE] [PRICE] =>"
weigth_sp:
.string "\n[SWEET POTATOE] [WEIGTH] =>"
price_ip:
.string "\n[IRISH POTATOE] [PRICE] =>"
weigth_ip:
.string "\n[IRISH POTATOE] [WEIGTH] =>"
price_rc:
.string "\n[RICE] [PRICE] =>"
weigth_rc:
.string "\n[RICE] [WEIGTH] =>"
price_fl:
.string "\n[FLOUR] [PRICE] =>"
weigth_fl:
.string "\n[FLOUR] [WEIGTH] =>"
balance:
.string "\n[PAID] [BALANCE] =>%d\n"
integer:
.string "%d"
error:
.ascii "\n UNABLE TO CONNECT \n TO SERVER TRY AGAIN LATER \n\n\n"
#-------------------------------------------------------
#-------------------------------------------------------
#start the section containing uninitialed variable
#the empty variale is declared here
#-------------------------------------------------------
.section .bss
.lcomm i , 4 #i variable containing 4 bytes of memory
#-------------------------------------------------------
#-------------------------------------------------------
#start the section containing instruction code
#executing code starting in text section
#--------------------------------------------------------
#--------------------------------------------------------
.section .text
.globl executing
executing:
push ebp
mov ebp , esp
sub esp , 40
#---------------------------------------------------------
#printing the user product available
#on online customer product
#---------------------------------------------------------
push offset user_menu
call _printf
add esp , 0x04
push offset choose
call _printf
add esp , 0x04
#---------------------------------------------------------
#asking the user to choose product are need to buy
#---------------------------------------------------------
lea eax , dword ptr ss:[ebp-0x04]
push eax
push offset integer
call _scanf
add esp , 0x08
#----------------------------------------------------------
#testing the user is input valid product
#-----------------------------------------------------------
cmp dword ptr ss:[ebp-0x04] , 0x04
jle calculate #if the user inputed the value are
#less than or equal to 4 jump to calculate

#-------------------------------------------------------------
#else printing the user is choosed error code
#-------------------------------------------------------------
error_code:
push offset message
call _printf
add esp , 0x04
jmp exit_code
#--------------------------------------------------------------
#the engine that help user to calculate all user computing
#the user can see the balance of their Money tha will pay fo company
#---------------------------------------------------------------
calculate:
cmp dword ptr ss:[ebp-0x04] , 0x00
je error_code
cmp dword ptr ss:[ebp-0x04] , 0x01
je s_potatoes
cmp dword ptr ss:[ebp-0x04] , 0x02
je i_potatoes
cmp dword ptr ss:[ebp-0x04] , 0x03
je rice_bal
cmp dword ptr ss:[ebp-0x04] , 0x04
je flour_bal
s_potatoes:
push offset message
call _printf
add esp , 0x04
push offset price_sp
call _printf
add esp , 0x04
lea eax , dword ptr ss:[ebp-0x08]
push eax
push offset integer
call _scanf
add esp , 0x08
push offset weigth_sp
call _printf
add esp , 0x04
lea eax , dword ptr ss:[ebp-0x0c]
push eax
push offset integer
call _scanf
add esp , 0x08
mov eax , dword ptr ss:[ebp-0x08]
imul eax , dword ptr ss:[ebp-0x0c]
push eax
push offset balance
call _printf
add esp , 0x08
jmp exit_code

i_potatoes:
push offset message
call _printf
add esp , 0x04
push offset price_ip
call _printf
add esp , 0x04
lea eax , dword ptr ss:[ebp-0x10] #ebp-16
push offset integer
call _scanf
add esp , 0x08
push offset weigth_ip
call _printf
add esp , 0x04
lea eax , dword ptr ss:[ebp-0x14] #ebp-20
push eax
push offset integer
call _scanf
add esp , 0x08
mov eax , dword ptr ss:[ebp-0x10]
imul eax , dword ptr ss:[ebp-0x14]
push eax
push offset balance
call _printf
add esp , 0x08
jmp exit_code
rice_bal:
push offset message
call _printf
add esp , 0x04
push offset price_rc
call _printf
add esp , 0x04
lea eax , dword ptr ss:[ebp-0x18] #ebp-24
push eax
push offset integer
call _scanf
add esp , 0x08
push offset weigth_rc
call _printf
add esp , 0x04
lea eax , dword ptr ss:[ebp-0x1c]
push eax
push offset integer
call _scanf
add esp , 0x08
mov eax , dword ptr ss:[ebp-0x18]
imul eax , dword ptr ss:[ebp-0x1c]
push eax
push offset balance
call _printf
add esp , 0x08
jmp exit_code
flour_bal:
push offset message
call _printf
add esp , 0x04
push offset price_fl
call _printf
add esp , 0x04
lea eax , dword ptr ss:[ebp-0x20]
push eax
push offset integer
call _scanf
add esp , 0x08
push offset weigth_fl
call _printf
add esp , 0x04
lea eax , dword ptr ss:[ebp-0x24]
push eax
push offset integer
call _scanf
add esp , 0x08
mov eax , dword ptr ss:[ebp-0x24]
imul eax , dword ptr ss:[ebp-0x20]
push eax
push offset balance
call _printf
add esp , 0x08
exit_code:
mov esp , ebp
pop ebp
ret

.globl _main
_main:
push ebp
mov ebp , esp
mov dword ptr [i] , 0x00
loop_i:
call executing
add dword ptr [i] , 1
loop_c:
cmp dword ptr [i] , 0x03
jl loop_i
mov eax , 0
mov esp , ebp
pop ebp
ret