8086 assembly language program to display an inverted pyramid using loop Edit
We will write code to display an inverted pyramid like the one below. Try this code first which displays same length lines 6 times. I had modified the article from the above link to display an inverted pyramid. Its simple code and easy to undertand.
********** ******** ****** *** *
Sample code in 8086 Assembly Language To Display An Inverted Pyramid
.model tiny .code org 100h main proc near mov characterperline,10 mov characterperlineforspace,1 mov cx,6 loop2: ; Loop 2 outer loop push cx ; you have to push the cx and pop it out before loop instruction to prevent the cx being over written by the inner loop cx mov cx,characterperline cmp cx,0 ; If cx is zero we have to display one * jne loop1 inc cx ; increment cx loop1: ; inner loop mov ah,02h ; Dos function 02h to Write character to STDOUT mov dl,'*' ; character to write int 21h ; dos interrupt 21h loop loop1 dec characterperline dec characterperline ; Code to print in next line mov ah,02h mov dl,0ah ; carriage return int 21h mov ah,02h mov dl,0dh ; line feed int 21h ; Code for space from line number 2 mov cx,characterperlineforspace space: mov ah,02h ; Dos function 02h to Write character to STDOUT mov dl,' ' ; character to write int 21h ; dos interrupt 21h loop space inc characterperlineforspace pop cx loop loop2 mov ah,4ch ; Dos function to terminate the return to dos mov al,00 ; return code int 21h ; dos interrupt 21 characterperline dw 0 characterperlineforspace dw 0 endp end main