简体   繁体   中英

Assembly working with strings, checking result

I'm not sure how to even formulate the question but I've recently started learning assembly and I've got to the point where I work with strings of bytes/words and my final result will as well be a string of bytes/words... My question is, how do I check that my program returned the correct result? Is there any way? I've just finished solving a problem that sounds like this: I have the string S: 1, 2, 3, 4, 5, 6 and I have to compose the string D whose elements represent the sum of each two consecutive bytes of S so D:3, 5, 7, 9, 11 How do I check that I got the right result?

If you want to check the correctness of your hand-written assembly implementation (which is a really good idea), you can write the equivalent program in a different language. Give both programs the same input, pipe each output into a file, and run a diff -utility on the files.
If you want to trace your program though its execution, you can run the program in a debugger. It won't have the amenities of a debugger with high-level source-code, but you should be able to get the debugger to display register contents and memory.
In gdb you can use i(nfo) reg(isters) to show register state.

A simple solution to check the result is to display as many chars in a line as specified in the string

lea si, d
mov cx, 4 ;replace size with the amount of elements in D; mustn't be zero
new_row:
push cx
mov al, 10
int 29h
mov al, 13
int 29h
lodsb
or al, al
jz e
mov cx, ax
xor ch, ch
mov al, 46 ;the character shown as many times as specified in the string (here: a dot . )
next_char:
int 29h ;the advantage of this function is, the output always shown at the screen, it cannot be pipelined.
loop next_char
e:
pop cx
loop new_row
exit:
mov al, 10
int 29h
mov al, 13
int 29h

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM