I have an intro to Assembly Programming class this semester. We just completed our first programs and it was super tedious. Yet strangely satisfying when I finished it. I was wondering how many other people have experience with it. What tips they could offer.
I'm doing all of my work on a virtual box setup with 32 bit windows xp with an intel core. Also using NASM to compile it all.
So here is my first super simple yet super long program
; Patrick McPartland
; Program: Assignment 2: Simple arithmetic
; & Input/Output
%include "asm_io.inc"
segment .data
prompt1 db "Please enter an integer: ", 0
prompt2 db "Please enter a second intger: ",0
sumMsg1 db "The sum ",0
sumMsg2 db " + ",0
sumMsg3 db " is: ",0
difMsg1 db "The difference is: ",0
difMsg2 db " - ",0
difMsg3 db " is: ",0
productMsg1 db "The product ",0
productMsg2 db " x ",0
productMsg3 db " is: ",0
divMsg1 db "The integer quotient ",0
divMsg2 db " / ",0
divMsg3 db " is: ",0
segment .bss
integer1 resd 1
integer2 resd 1
segment .text
global _asm_main
_asm_main:
enter 0,0
pusha
;Input prompts
mov eax, prompt1
call print_string
call read_int
mov [integer1], eax
mov eax, prompt2
call print_string
call read_int
mov [integer2], eax
;Addition math
mov eax, [integer1]
add eax, [integer2]
mov ebx, eax
;Output of addition
mov eax,sumMsg1
call print_string
mov eax, [integer1]
call print_int
mov eax, sumMsg2
call print_string
mov eax, [integer2]
call print_int
mov eax, sumMsg3
call print_string
mov eax,ebx
call print_int
call print_nl
;Subtraction math
mov eax, [integer1]
sub eax, [integer2]
mov ebx, eax
;Output of subtraction
mov eax,difMsg1
call print_string
mov eax, [integer1]
call print_int
mov eax, difMsg2
call print_string
mov eax, [integer2]
call print_int
mov eax, difMsg3
call print_string
mov eax, ebx
call print_int
call print_nl
;Multiplication math
mov eax,[integer1]
mov ebx,[integer2]
mul ebx
mov ebx, eax
;Output of multiplication
mov eax,productMsg1
call print_string
mov eax, [integer1]
call print_int
mov eax, productMsg2
call print_string
mov eax, [integer2]
call print_int
mov eax, productMsg3
call print_string
mov eax, ebx
call print_int
call print_nl
;Integer division math
mov eax, [integer1]
mov ebx, [integer2]
idiv ebx
mov ebx, eax
;Output of integer division
mov eax,divMsg1
call print_string
mov eax, [integer1]
call print_int
mov eax, divMsg2
call print_string
mov eax, [integer2]
call print_int
mov eax, divMsg3
call print_string
mov eax, ebx
call print_int
popa
mov eax, 0
leave
ret
Here is what it outputs along with compiling it.
