Reputation: 33
I would like to print numbers in bigger ASCII-Matrices with a NASM-program. Like a dot-matrix-display but only with ASCII-Characters. In my program, I can just display one number, but I fail to display two numbers in one row.
section .data
four: dw 0xdb,0x20,0x20,0xdb,0x0A,0xdb,0x20,0x20,0xdb,0x0A,0xdb,0xdb,0xdb,0xdb,0x0A,0x20,0x20,0x20,0xdb,0x0A,0x20,0x20,0x20,0xdb ; 4 in ASCII-Signs
fourlen equ $-four
section .bss
a1 resw 200 ;space to store the ASCII-Matrix-Numbers
section .text
global _start
_start:
mov eax,four
mov [a1],eax ;first 4 in a1
mov [a1+fourlen],eax ;second four in a1
mov eax,4
mov ebx,1
mov ecx,[a1] ;display 44 -> fail
mov edx,200
int 80h
end:
mov eax,1
mov ebx,0
int 80h
I want to store every ASCII-number in a1
, to be able to display the ASCII-numbers in a single row. But that fails. Any help/tips to realise that?
Upvotes: 2
Views: 249
Reputation: 11018
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:
mov edx,200
by mov edx,2*fourlen
.0x0A
to four
. Or preferrably two 0x0A
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 to four
to move the cursor up 4 lines, to compensate for the 4 linefeeds in four
. 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.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 from a1
. Whether you actually want to do this depends on your choice concerning my previous remark.Upvotes: 1