T
T
thatmaniscool2020-03-14 03:03:29
assembler
thatmaniscool, 2020-03-14 03:03:29

How to display 4 digit decimal number in assembler?

Hello!
I wrote a small program that converts the 16th code to decimal while preserving the bit depth.
But I ran into the problem that if there is a zero in the number, then it does not display it. How to solve this problem, it does not reach me.

#make_COM#

; COM file is loaded at CS:0100h
ORG 100h

MOV BP, 3021
MOV DI, 0


l1:
MOV AX, BP
CMP AX, 9999
JA mCX1
CMP AX, 999
JA mCX2
CMP AX, 99
JA mCX3
CMP AX, 9
JA mCX4
CMP AX, 0
JA mCX5



; Первая цифра
mCX1:
MOV DI, 1
MOV BX, 10000
XOR DX, DX
DIV BX
MOV BP, DX
ADD AX, 30h
MOV DL, AL
MOV AH, 2h
INT 21h
JMP l1

; Вторая цифра
mCX2:
MOV DI, 2
MOV BX, 1000
XOR DX, DX
DIV BX
MOV BP, DX
ADD AX, 30h
MOV DL, AL
MOV AH, 2h
INT 21h
JMP l1

; Третья цифра
mCX3:
CMP DI, 2
JNE st1
MOV AH, 2
MOV DL, 30h
INT 21h
st1:
MOV DI, 3
MOV BX, 100
XOR DX, DX
DIV BX
MOV BP, DX
ADD AX, 30h
MOV DL, AL
MOV AH, 2h
INT 21h
JMP l1

; Четвертая цифра
mCX4:
CMP DI, 3
JNE st2
MOV AH, 2
MOV DL, 30h
INT 21h
st2:
MOV DI, 4
MOV BX, 10
XOR DX, DX
DIV BX
MOV BP, DX
ADD AX, 30h
MOV DL, AL
MOV AH, 2h
INT 21h
JMP l1

; Пятая цифра
mCX5:
CMP DI, 4
JNE st3:
MOV AH, 2
MOV DL, 30h
INT 21h
st3:
MOV DI, 5
MOV BX, 1
XOR DX, DX
DIV BX
MOV BP, DX
ADD AX, 30h
MOV DL, AL
MOV AH, 2h
INT 21h


HLT
stop

If there is no zero in the value, then everything is displayed perfectly.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Kuts, 2020-03-14
@fox_12

- put the digit in the least significant bit
- add 48 (in ascii codes of numbers start with 48)
- display the resulting character on the screen
З.Ы. Read about organizing cycles. It's kind of complicated for you.

1
15432, 2020-03-14
@15432

Look at the last comparison. The jump occurs only if the number is greater than zero (Jump Above).
there is no comparison needed at all, just JMP mCX5

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question