-1

I am new in assembly language. I just need some advice or tips on how can I declare counter loop that decrement the input number. For example, input = 5, print = 55555.5555.555.55.5

include emu8086.inc
org 100h

print 'Input a number: '

MOV AH,01H ;input
INT 21H
MOV BL,AL

MOV DL,BL

SUB BL,30H
MOV CL,BL

printn

print 'Output: '
DISP:
MOV AH,02H
INT 21H

DEC CL
JNZ DISP

MOV AH,4CH
INT 21H
Input: 5
Output: 55555

This is very basic for you guys, and for me it is very hard to learn but I won't stop learning. I just need some advice for this one.

Bro
  • 1
  • 1
  • `MOV AH,01H/INT 21H` piece stores input in `AL`, `MOV BL,AL/SUB BL,30H/MOV CL,BL` sets `CL` to `input - 30H`, `DISP:/DEC CL/JNZ DISP` is a cycle on `CL` value. So there is already a cycle, dependent on the input. – nevilad Apr 11 '21 at 10:55
  • Yes there is, the **output = 55555** is the result of cycle but how about the other cycle that turns into decrement? How can I make the output to `55555, 5555, 555, 55, 5`? – Bro Apr 11 '21 at 11:10
  • Add value input (`INT 21H`) for the output count and change your cycle counter (`CL`) to that value. – nevilad Apr 11 '21 at 11:16
  • Can you guide me by adding it to my codes? I get what you've said but I cannot do it. because I'm just starting to learn. – Bro Apr 11 '21 at 12:04

1 Answers1

0

The solution can be so

include emu8086.inc
org 100h

print 'Input a number: '

MOV AH,01H ;input digit to output 
INT 21H
MOV DL,AL

MOV AH,01H ;input number of times to output 
INT 21H
MOV CL,AL
SUB CL,30H

printn

print 'Output: '
DISP:
MOV AH,02H
INT 21H

DEC CL
JNZ DISP

MOV AH,4CH
INT 21H

This solves the problem of different inputs, but there is no checking if input is valid.

nevilad
  • 932
  • 1
  • 7
  • 14