我正在尝试根据N值打印一个星号三角形。我这里的代码只打印一整行N *。我要找的最终结果是:
*
**
***
****
If N = 4
我现在的代码
.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"
任何人都可以帮助我完成这项工作吗?
答案 0 :(得分:-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"
答案 1 :(得分:-1)
在CS:0100h加载COM文件 ORG 100h
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 停: .EXIT
;只需将41h(A)更改为*(十六进制)
答案 2 :(得分:-2)
在CS:0100h加载COM文件 ORG 100h
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 停: .EXIT