12,896,175 members (52,998 online)

# [Assembly] How do I loop this?

I was working on some Assembly code, and I need to separate the digits of my WORD variable (12345). I've done this, and I am unsure as to how to loop this:

```org 100h

section .text

start:
mov bx, output  ; put address of output into BX
mov ax, [num]   ; put 16-bit value stored at num in AX
sub dx, dx      ; let DX = 0

mov cx, 10000   ; Divide AX by 10000
div cx          ; result in AX, remainder in DX
add al, 30h     ; ASCII '1' = 49 (or 31h) so add 30h
mov [bx], al    ; Store ASCII char in output
inc bx          ; point to next char in output
mov ax, dx      ; move remainder of last division into AX
sub dx, dx      ; clear remainder

mov cx, 1000    ; Divide AX by 1000
div cx
mov [bx], al
inc bx
mov ax, dx
sub dx, dx

mov cx, 100     ; Divide AX by 100
div cx
mov [bx], al
inc bx
mov ax, dx
sub dx, dx

mov cx, 10      ; Divide AX by 10
div cx
mov [bx], al
inc bx
mov ax, dx
sub dx, dx

mov cx, 1
div cx
mov [bx], al

mov bx, output  ; get address of first char in ouput

myloop:
mov dl, [bx]    ; get char at address in BX
inc bx          ; point BX to next char in message
cmp dl, 0       ; Is DL = null (that is, 0)?
je  quit        ; If yes, then quit
mov ah, 06      ; If no, then call int 21h service 06h
int 21h         ;    to print the character
jmp myloop      ; Repeat for the next character

quit:
; DONE!
int 20h

section .data
num dw  12345
output  db  0,0,0,0,0,0```
Tags: (untagged)

## Preview

2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).