As title says
Just trying to read in values and store them in an array
Then call print function to print them out
As of now the program works, but only prints out the last value entered and the other outputs are 0's
here is the code...
%include "asm_io.asm"
segment .bss
array1 resd 6
array2 resd 6
array3 resd 6
segment .data
prompt1 db "Enter your number(if done enter: 0 ) : ", 0
aprompt1 db "Array1 Contents: ", 0
aprompt2 db "Array2 Contents: ", 0
aprompt3 db "Maximum Array Entries Reached: " , 0
dprompt db "Goodbye ! ", 0
segment .text
extern puts, _printf, scanf, dump_line
global asm_main
asm_main:
enter 0,0
pusha
;Declare Array1
pusha
push 6 ;declares max size of array1
push 0 ;indicates number of elements in array1
push array1 ;declares starting address of array1
mov eax, prompt1
call print_string
call print_nl
call read_sarray32
call print_sarray32
mov eax, dprompt
call print_string
pop edx
pop edx
pop edx
popa
leave
ret
;Declare Array2
;pusha
;push 6
;push 0
;push array2
;mov eax, prompt1
;call print_string
;
; call read_sarray32
;Declare Array3
; pusha
; push 6
; push 0
; push array3
; mov eax, prompt1
; call print_string
;
; call ;to adding array1 and array2
; popa
read_sarray32:
enter 0,0
pusha
mov ebx, 0 ;initialize ebx at 0
mov ebx, [esp+40] ;array starting position
mov edx, [esp+48] ;array max size
mov ecx, 0
read_loop:
mov eax, prompt1
call print_string
call read_int
inc ecx ;increment counter
cmp eax, 0
jz Done
jmp continue_loop
continue_loop:
mov [ebx], eax ;move value into memory slot ebx
add edx, 4 ;move to next location for db words
cmp ecx, 6 ; did i reach maximum values of array size?
jz maximum_entries
jmp read_loop
maximum_entries:
mov eax, aprompt3
call print_string
jmp Done
Done:
mov [esp+44], ecx ;moves counter value back to stack
popa
leave
ret
print_sarray32:
enter 0,0
pusha
mov ecx, 0 ;initialize counter to 0
mov ebx, [esp+40] ;move starting location to ebx
mov edx, [esp+48] ;move # items to edx
mov eax, aprompt1
call print_string
call print_nl
print_loop:
mov eax, [ebx] ;move value of index 0 of array to eax
call print_int ;print out number
call print_nl
add ebx, 4 ; moved ebx location to next slot
inc ecx ; counter is incremented by 1
cmp ecx, 6
jz print_sarrayDone
jmp print_loop
print_sarrayDone:
popa
leave
ret