简体   繁体   中英

Print spaces between every numbers that's printed in 8086 Assembly

I want to print a 2D array in 8086 Assembly and I am stuck in the last few steps of the assignment.

For example, I need my output to be:

1 2 3 4 5
6 7 8 9 10

instead of

12345
678910

I already have a nest loop for printing out the array but I don't know how to print spaces between the numbers. Thanks!

let's assume you have a loop, that prints numbers 1-10

mov ax,1

L_again:
    push ax
    call printAX

    pop ax
    inc ax
    cmp ax,10
    jbe L_again
ret

then all you need is to add a "print a space" right after printing AX

mov ax,1

L_again:
    push ax
    call printAX
    call printSpace

    pop ax
    inc ax
    cmp ax,10
    jbe L_again
ret

which could look like this (eg for DOS). for small functions like this you could of course simply add the few instructions right into the loop itself

printSpace:
    mov dl, ' '
    mov ah, 2
    int 21h
    ret

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