Skip to content

Commit

Permalink
Fix array printer only printing the first element
Browse files Browse the repository at this point in the history
  • Loading branch information
ChillerDragon committed Aug 2, 2024
1 parent a50f551 commit 6e8d39c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/logger.asm
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,23 @@ print_any_int:

call print_open_bracket

mov ecx, 0
; counter
mov rcx, 0

; 64 bit pointer to integer
mov rax, [rbp-16]

%%loop_elements:
inc ecx

; 64 bit pointer to integer
mov rax, [rbp-16]
; 32 bit element size
mov rdi, 0
mov dword edi, [rbp-8] ; printed and verified to be 1
call print_any_int

; increment pointer by size
add rax, rdi

cmp ecx, [rbp-4]
je %%loop_elements_skip_comma
call print_comma
Expand Down
43 changes: 43 additions & 0 deletions tests/print_int_array_test.asm
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
%include "tests/assert.asm"

_start:
test_1_byte_int_array:
; no asserts just checking if we crash or not

; stack allocated array of 3 elements
Expand All @@ -17,4 +18,46 @@ _start:
print_int_array rax, 1, 3

mov rsp, rbp

test_2_byte_int_array:
call print_space

; no asserts just checking if we crash or not

; stack allocated array of 3 elements
; every element is a one byte integer
mov rbp, rsp
sub rsp, 6
mov word [rbp-6], 666
mov word [rbp-4], 777
mov word [rbp-2], 888

; rax=buf 2=element size 3=array size
lea rax, [rbp-6]

print_int_array rax, 2, 3

mov rsp, rbp

test_4_byte_int_array:
call print_space

; no asserts just checking if we crash or not

; stack allocated array of 3 elements
; every element is a one byte integer
mov rbp, rsp
sub rsp, 12
mov dword [rbp-12], 0xaabbccdd
mov dword [rbp-8], 0xaabbccdf
mov dword [rbp-4], 0xaabbccdd

; rax=buf 4=element size 3=array size
lea rax, [rbp-12]

print_int_array rax, 4, 3

mov rsp, rbp

exit 0

0 comments on commit 6e8d39c

Please sign in to comment.