ics312_first_v0.asm [Download]
; This simple program simply adds to 32-bit integers together
; and stores the results back in memory
segment .data
integer1 dd 15 ; first int
integer2 dd 6 ; second int
segment .bss
result resd 1 ; result
segment .text
global asm_main
asm_main:
enter 0,0
pusha
mov eax, [integer1] ; eax = first integer
add eax, [integer2] ; eax += second integer
mov [result], eax ; result = eax
popa
mov eax, 0
leave
ret
ics312_first_v1.asm [Download]
; This simple program simply adds to 32-bit integers together
; and stores the results back in memory
%include "asm_io.inc"
segment .data
integer1 dd 15 ; first int
integer2 dd 6 ; second int
segment .bss
result resd 1 ; result
segment .text
global asm_main
asm_main:
enter 0,0
pusha
mov eax, [integer1] ; eax = first integer
add eax, [integer2] ; eax += second integer
mov [result], eax ; result = eax
call print_int ; print the result
popa
mov eax, 0
leave
ret
ics312_first_v2.asm [Download]
; This simple program simply adds to 32-bit integers together
; and stores the results back in memory
%include "asm_io.inc"
segment .data
msg1 db "Enter a number: ", 0
msg2 db "The sum of ", 0
msg3 db " and ", 0
msg4 db " is: ", 0
segment .bss
integer1 resd 1 ; first integer
integer2 resd 1 ; second integer
result resd 1 ; result
segment .text
global asm_main
asm_main:
enter 0,0 ; setup
pusha ; setup
mov eax, msg1 ; note that this is a pointer!
call print_string
call read_int ; read the first integer
mov [integer1], eax ; store it in memory
mov eax, msg1 ; note that this is a pointer!
call print_string
call read_int ; read the second integer
mov [integer2], eax ; store it in memory
mov eax, [integer1] ; eax = first integer
add eax, [integer2] ; eax += second integer
mov [result], eax ; store the result
mov eax, msg2 ; note that this is a pointer
call print_string
mov eax, [integer1] ; note that this is a value
call print_int
mov eax, msg3 ; note that this is a pointer
call print_string
mov eax, [integer2] ; note that this is a value
call print_int
mov eax, msg4 ; note that this is a pointer
call print_string
mov eax, [result] ; note that this is a value
call print_int
call print_nl
popa ; cleanup
mov eax, 0 ; cleanup
leave ; cleanup
ret ; cleanup
ics312_littleendian.asm [Download]
; This simple program demonstrate that the processor
; uses Little Endian
%include "asm_io.inc"
segment .data
bytes dd 06C697665h ; "live"
end db 0 ; null
segment .text
global asm_main
asm_main:
enter 0,0
pusha
mov eax, bytes ; note that this is an address
call print_string ; print the string at that address
call print_nl ; print a new line
mov eax, [bytes] ; load the 4-byte value into eax
dump_mem 0, bytes, 1 ; display the memory
dump_regs 0 ; display the registers
pusha
popa
mov eax, 0
leave
ret