howard howard
howard howard

Reputation: 59

Printing multiple triangles on MASM x86 (16 bit)

So I am trying to write a program in MASM x86 (8086) that will printout a series of right triangles built of asterisks “”. I am using loops to print out the triangles. I am trying to make each of the triangles 3 to 9 asterisks high and the same number across, but in different configurations. I got it to only print one triangle though. After my 1st triangle is printed, it just keeps looping asterisks "" indefinitely. Here is some of my code:

 mov ah, 09h ;prints string
  mov dx, offset input
  int 21h

  mov ah, 01h ;reads in character
  int 21h

  sub al, '0' ;is gunna read into lower half by default
  mov ah, 0 ;blanking higher half of register so that way it doesnt throw off program
  mov size, ax
  mov cx, ax 
  mov bx, cx 
  push bx

  mov ah, 02h
  mov dl, 13
  int 21h  
  mov dl, 10
  int 21h


 lines:
    push cx 

  stars:
   mov ah, 02h
   mov dl, '*'
   int 21h


  loop stars 

  mov ah, 02h
  mov dl, 13
  int 21h  
  mov dl, 10
  int 21h

  pop cx 

  loop lines

  mov bx, size 

  mov ax, 4c00h
  int 21h

Im guessing I have to create another register to hold the variable and possibly create another loop.
My question is, do I have to pass the user input into another register? And if so, how can I pass it?

Upvotes: 2

Views: 875

Answers (1)

Fifoernik
Fifoernik

Reputation: 9899

You've already put the user input in the SIZE variable, so that's fine.
After the 1st triangle is drawn you put this variable back in the CX register, change it a bit (more or less) and repeat the code for the triangle:

; First user defined triangle

    mov ah, 02h
    mov dl, 13
    int 21h  
    mov dl, 10
    int 21h
lines:
    push cx 
stars:
    mov ah, 02h
    mov dl, '*'
    int 21h
    loop stars 
    mov ah, 02h
    mov dl, 13
    int 21h  
    mov dl, 10
    int 21h
    pop cx 
    loop lines

; Take back the size and change it a bit

    mov cx, size
    add cx, 5

; Second bigger triangle

    mov ah, 02h
    mov dl, 13
    int 21h  
    mov dl, 10
    int 21h
lines:
    push cx 
stars:
    mov ah, 02h
    mov dl, '*'
    int 21h
    loop stars 
    mov ah, 02h
    mov dl, 13
    int 21h  
    mov dl, 10
    int 21h
    pop cx 
    loop lines

Upvotes: 1

Related Questions