INCLUDE Irvine32.inc
.code
main PROC
mov ecx, 1
mov ebp, 6 ;used as reverse counter for blank spaces
L1: call proc2
call Proc1
call CRLF ;New line
inc ecx ;increments ecx
cmp ecx, 6 ;Limits ecx to n
jbe L1 ;If (CX <= n) Repeat
exit
main ENDP
proc1 PROC USES ecx
mov al, 'A' ;Stores character in al
L2: call WriteChar ;Writes character
inc al ;Increments al
loop L2
ret
proc1 ENDP
proc2 PROC
push ebp ;Preserve current spaces counter
mov al, ' ' ;Space to print
L3: call WriteChar ;Print space
dec ebp ;Decrease counter
jnz L3 ;If counter > 0 repeat
pop ebp ;Restore spaces counter
dec ebp ;Decrease one space for the next line
ret
proc2 ENDP
END main
我正在尝试输出两个三角形,如下所示。我似乎无法让两个三角形互相镜像,我只是在右边的tringle。任何帮助将非常感激。
A A
AB BA
ABC CBA
ABCD DCBA
ABCDE EDCBA
ABCDEF FEDCBA
答案 0 :(得分:1)
上述代码存在许多问题。 proc1从ABCDEF输出N个第一个字符,proc2输出6-N个空格。所以你得到的应该是:
A
AB
ABC
ABCD
ABCDE
注意第6行ebp为0,因此proc 2将输出2 ^ 32个空格。
你应该在主循环中有这样的东西(注意:我假设你想要6行,所以比较ecx到7并将ebp初始化为7):
L1: call proc1
mov ah, al
call Proc2
mov al, ah
call Proc3
call CRLF ;New line
inc ecx ;increments ecx
cmp ecx, 7 ;Limits ecx to n
jbe L1 ;If (CX <= n) Repeat
proc3是:
proc3 PROC USES ecx
dec al ;al already contains the last output char+1
L2: call WriteChar ;Writes character
dec al ;Decrements al
loop L2
ret
proc1 ENDP
在proc2中,你应该在每次迭代中输出2个空格,如:
L3: call WriteChar ;Print space
call WriteChar ;Print space
dec ebp ;Decrease counter
jnz L3 ;If counter > 0 repeat