-1

I am trying to print a triangle of asterisks based on a value of N. The code I have here will just print an entire row of N *'s. The end result i am looking for is:

*
**
***
****
If N = 4

The code I have right now

       .ORIG x3000

        LD   R1, N
        NOT  R1, R1
        ADD  R1, R1, #1 ; R1 = -N

        AND     R2, R2, #0  ; R2 = 0
LOOP    ADD R3, R2, R1  ; while (R2 < N)
        BRzp     
        LD   R0, STAR   ; R0 = *
        OUT             ; Write *
        LEA  R0, NEWLN  ; R2 = R2 + 1
        PUTS
        ADD  R2, R2, #1 ; 
        BRnzp    LOOP
ELOOP
        LEA  R0, NEWLN
        PUTS

STOP    HALT        

N       .FILL    4
STAR    .FILL    x2A
NEWLN   .STRINGZ "\n"

Can anyone help me out with accomplishing this?

connor moore
  • 611
  • 1
  • 8
  • 18
  • How does that code do (or not do) what you want? – Jongware Oct 30 '14 at 23:55
  • The code here will print N *'s in a single row – connor moore Oct 31 '14 at 00:00
  • So your call to `NEWLN` does not work, or is possibly called at the wrong time? Did you step through the code with a debugger? – Jongware Oct 31 '14 at 00:04
  • No, the new line works for the way this code is set up, I now want to modify it to act the way I need it to now. – connor moore Oct 31 '14 at 00:06
  • If the PUTS worked, you should get the asterisks in a single column. Maybe you should put out the newline just like you put out the asterisk. Then you can make an outer loop that gives different values for r2 to print different lengths of asterisk-bars. Oh, and take the newline printing out of the inner loop and put it after the loop. – turboscrew Oct 31 '14 at 07:27

3 Answers3

-1
;; Author: Chris Wickell


.ORIG x3000

    LD   R1, N
    NOT  R1, R1
    ADD  R1, R1, #1 ; R1 = -N

    AND     R2, R2, #0  ; R2 = holds number of *'s to be printed

    LOOP    LEA  R0, NEWLN

    PUTS    

    ADD R3, R2, R1  ; while (R2 < N)

    BRzp ELOOP

    ADD  R5, R5, #1 ;

    ADD  R4, R4, #1

    FLOOP   LD   R0, STAR   ; R0 = *

    OUT             ; Write *
    ADD R5, R5, #-1

    BRp FLOOP

    ADD R5, R4, #0

    ADD  R2, R2, #1 ;

    BRnzp    LOOP
    ELOOP
    LEA  R0, NEWLN

    PUTS

    STOP    HALT        

N       .FILL    6

STAR    .FILL    x2A

NEWLN   .STRINGZ "\n"
Devolus
  • 21,661
  • 13
  • 66
  • 113
Chris Wickell
  • 41
  • 1
  • 1
  • 10
-1

make_COM

; COM file is loaded at CS:0100h ORG 100h

MOV AH,0EH CALL A4 CALL A3 CALL A2 CALL A1 JMP STOP

A4: MOV AL,41H

INT 10H

A3: MOV AL,41H INT 10H A2: MOV AL,41H INT 10H A1: MOV AL,41H INT 10H MOV AL,0DH INT 10H MOV AL,0AH INT 10H RET STOP: .EXIT

;just change 41h(A) to *(in hexadecimal)

-2

make_COM

; COM file is loaded at CS:0100h ORG 100h

MOV AH,0EH CALL A4 CALL A3 CALL A2 CALL A1 JMP STOP

A4: MOV AL,41H

INT 10H

A3: MOV AL,41H INT 10H A2: MOV AL,41H INT 10H A1: MOV AL,41H INT 10H MOV AL,0DH INT 10H MOV AL,0AH INT 10H RET STOP: .EXIT