0

I tried making an assembly code that prints out the first 10 numbers in the fibonacci sequence but instead I get some random characters like smiley faces. It's the first time I do this if somebody can help me with this thank you!

.model small
.data
n dw 10

.code
mov ax, @data
mov ds, ax

mov ax, 1
mov bx, 0

mov cx, n

urm: 

mov ah, 2
  mov dx, ax
int 21h

mov si, ax
add ax, bx
mov bx, si  

dec cx

loop urm
mov ah, 4ch
int 21h
end

1 Answers1

0

When you invoke DOS service WRITE CHARACTER TO STANDARD OUTPUT for the first time with

   mov ah, 2
   mov dx, ax
   int 21h

register dl contains the number 1, which is not digit "1". You would have to convert it to a character
by ADD DL,"0". Unfortunately it is that easy only for numbers 0..9. See this answer how to convert greater binary numbers to a decimal format.

Also look at

dec cx
loop urm

This looks suspicious, because the instruction loop decrements cx by itself.

vitsoft
  • 5,515
  • 1
  • 18
  • 31