You reserve a buffer of 200 words, so I suppose you have got the intention to copy the entire block of data from four
to a1
. In assembly, this is not going to be done by a single mov
.
Your instructions copy two pointers referencing four
into a1
:
mov eax,four
mov [a1],eax ; first 4 in a1
mov [a1+fourlen],eax ; second four in a1
Instead you should copy the contents of four
into a1
:
cld
mov edi,a1 ; destination address
mov esi,four ; source address
mov ecx,fourlen ; number of bytes
rep movsb ; copy data from source to destination, first time
; do NOT adjust edi; it's already at the right address!
mov esi,four ; same source address
mov ecx,fourlen ; number of bytes
rep movsb ; copy data from source to destination, second time
In line with this, you should direct sys_write (i.e. your first int 80h
) to a1
, not to the first of the two pointers you originally stored in a1
. So instead of:
mov ecx,[a1]
do this:
mov ecx,a1
Additional remarks:
- You should only output what you copied; replace
mov edx,200
bymov edx,2*fourlen
. - You will notice the visual position of the second 'four' is not correct. How to fix this, depends on whether you want to print horizontally or vertically. If you want the second digit underneath the first one, then you should add a trailing
0x0A
tofour
. Or preferrably two0x0A
s, to keep some space between the two digits. If you want the two fours to be on the same line, then you will have to append some ANSI escape codes tofour
to move the cursor up 4 lines, to compensate for the 4 linefeeds infour
. If you do not want to use escape codes, then you will have to refactor your code so that it writes all digits together, line by line. - One might consider
a1
a waste of memory, and copying your data there a waste of CPU time. You might as well use two separate print calls, straight froma1
. Whether you actually want to do this depends on your choice concerning my previous remark. - You are using 16-bit words to store characters, which is fine if you want your output to be UTF-16-encoded. The terminal window on my system expected UTF-8; some more adjustments were needed there.