我正在开发一个玩具 NASM 程序,它将把特定程序中的所有值相加。我现在正在玩 NASM,因为我正在构建我的程序以了解一切是如何工作的。
到目前为止,在我的程序中,我已经放置了一系列显示“有效”的输出,这样我就可以缩小错误所在的范围。
目前我希望看到五份“工作”的打印件,但我只看到四份。显然,下面的代码Output:
无法打印,但我一生都无法弄清楚原因。
segment .data
;studentInfo: db 10,'Program by Raphael Stein', 10, '6079652', 10, 10 ;
;infoLen: equ $-studentInfo
NUM_ROWS: equ 5
NUM_COLUMNS: equ 5
NUM_ROW_BYTES: equ 10
;Default matrix
matrix: dw 5, 4, 9, 7, 2
dw 1, 4, 6, 8, 7
dw 9, 9, 2, 3, 7
dw 6, 5, 8, 3, 4
dw 1, 2, 8, 2, 6
matrixLen: equ $-matrix
sum: db "The sum of the last column is: ", 10
;FOR TESTING
works: db 'Works!', 10
worksLen: equ $-works
segment .bss
counter resb 1
segment .text
global main
main:
;------------------------------------------------------------------------
mov eax, 4 ; system call 4
mov ebx, 1 ; standard output
mov ecx, works ; Works! 1
mov edx, worksLen
int 0x80
;-------------------------------------------------------------------------
;mov CX, NUM_ROWS ;Works!
mov ECX, counter
sub AX, AX
sub EBX, EBX
mov ESI, NUM_COLUMNS-1
;------------------------------------------------------------------------
mov eax, 4 ; system call 4
mov ebx, 1 ; standard output
mov ecx, works ; Works! 2
mov edx, worksLen
int 0x80
;------------------------------------------------------------------------
sum_loop:
add EAX, [matrix + EBX + ESI*2]
add EBX, NUM_ROW_BYTES
add ECX, 1
cmp EAX,ECX
mov esi, eax
jge Output
LOOP sum_loop
;------------------------------------------------------------------------
mov eax, 4 ; system call 4
mov ebx, 1 ; standard output
mov ecx, works ; Works! 3
mov edx, worksLen
int 0x80
;-------------------------------------------------------------------------
Output:
mov eax, 4
mov ebx, 1
mov ecx, works
mov edx, worksLen
int 0x80
;------------------------------------------------------------------------
mov eax, 4 ; system call 4
mov ebx, 1 ; standard output
mov ecx, works ; Works! 4
mov edx, worksLen
int 0x80
;-------------------------------------------------------------------------
EXIT:
mov eax, 1
xor ebx, ebx
int 0x80