The task is to write an exe program (16 bit) that will display a prerecorded string (we use variables) in the following order. In the first line 1 letter from the line, in the second 2, in the third 3, etc. to the last character in the variable string.
Can anyone help as I don't understand this assembler at all((
That's all I'm capable of:
.MODEL TINY
.STACK 100h
code:
xor cx, cx
mov cl, 5
@1: mov dx, mess1
add dx, cx
mov ah, 9
int 21h
mov dx, offset crlf
mov ah, 9
int 21h
sub cx, 1
cmp cl, 0
jg @1
mov ah,04Ch
mov al,1h
int 21h
mess1 db "Artem$"
crlf db 10, 13, "$"
end code
You will need two DOS functions: AH=9 WRITE $-TEMINATED STRING TO STANDARD OUTPUT
and AH=2 WRITE CHARACTER FROM DL TO STANDARD OUTPUT.
Let's load one character to DL
, print it using INT21h/AH=2
, then print the string crlf
using INT21h/AH=9
and repeat in the loop CX
times.
code: ; Let CX keep the number of characters in mess1.
xor cx, cx
mov cl, 5 ; OK, but it's shorter to use mov cx,5 instead.
This is wrong, we need the register DL for other purpose.
; @1:mov dx, mess1
; add dx, cx
; mov ah, 9
; int 21h
Let's use other register to keep the address of each character, preferably register SI
:
mov si, offset mess1
The main loop starts here:
@1: mov dl,[si] ; Load one character to DL.
inc si ; Prepare the address of the next character.
mov ah,2 ; Print the character from DL.
int 21h
Now it's time to print crlf
as a string:
mov dx,offset crlf
mov ah,9
int 21h
Loop to print the remaining characters. SI points to the next character, CX is the loop counter.
sub cx, 1
cmp cl, 0
jg @1
This could work but more elegant is loop @1
or
dec cx
jnz @1
All five characters were printed on new lines. Now it's time to terminate the program.
mov ah,04Ch
mov al,1h
int 21h
.MODEL TINY
produces DOS COM program which may be alternatively terminated with a simple instruction ret
.