I have a task to write an Intel 8086 assembly language program that displays a pyramid of numbers without using INT 10h instructions. The result should look like in the screenshot: pyramid
This is my current code and the result
Progr segment
assume cs:Progr, ds:dane, ss:stosik
start:
mov ax, dane
mov ds, ax
mov ax, stosik
mov ss, ax
mov ax, offset szczyt
mov sp, ax
; Clear screen
mov ax, 0B800h
mov es, ax
xor di, di
mov cx, 2000
xor ax, ax
rep stosw
mov bl, 5
mov bh, 0
mov dh, 1
mov dl, 40
mov al, 65
mov cx, 1
mov di, 24
piramida:
push cx
wiersz: mov ah, bl
shl bx, 1
add bx, dx
shl bx, 1
mov es:[bx], ax
dec cx
jnz wiersz
pop cx
inc dh
dec dl
inc al
add cx,2
inc bl
dec di
jnz piramida
mov ah, 4Ch
mov al, 0
int 21h
Progr ends
dane segment
dane ends
stosik segment
dw 100h dup(0)
szczyt Label word
stosik ends
end start
This address calculation doesn't make sense! And because the BL register where you have stored the color attribute is part of the wider BX register, you are loosing the correct color information. Why do you even retrieve the color from BL and not just keep it in AH from the beginning? Is it because this whole program is based on an existing version that did use
int 10hfor character output? I'm sure about this as you have:and these are exactly what one would expect in the
int 10hsolution.The important lesson here is that you must first understand what a piece of code is doing before modifying it.
The regular 80 x 25 text screen uses 160 bytes for each row. You want the top of the pyramid in the middle of the first row, so initialize the address register to 80. Later, in order to descend one row, you will add 160 bytes to this address and subtract another 2 bytes because each level also starts one character more to the left.
There's really not much to it once you get these addresses right:
Make sure you understand the code this time, don't just copy/paste and learn nothing...