问题
Maybe this is stupid, but I'm pretty new to assembler, so please bear with me.
Is there any way to implement nested loops in assembler? An example would be much appreciated
I created this simple code out of an example, it outputs the letters: WVUTSR I modified it a bit in order to output it like this:
W
VW
UVW
TUVW
STUVW
RSTUVW
But instead, I get this:
WW
VV
UU
TT
SS
RR
Here's the code:
.model small
.stack 100h
.data
M DB 'W'
.CODE
MAIN PROC FAR
MOV AX, @DATA
MOV DS, AX
MOV AX, 003H
INT 10H
; for (CX = 6; CX != 0; CX--) { // PSEUDO CODE
; for (BL = 0; BL != 7-CX; BL++) {
; putchar(M+BL);
; }
; M--;
; putchar(10);
; putchar(13);
; }
MOV CX, 6
OUTER:
INNER:
MOV AL, 7
SUB AL, CL
CMP BL, AL
JE INNEREQUAL
MOV AH, 02
MOV DL, M
INT 21H
MOV DL, AL
INT 21H
INC BL
JNE INNER
INNEREQUAL:
DEC M
MOV AH, 2
MOV DL, 10
INT 21H
MOV DL, 13
INT 21H
LOOP OUTER
MOV AH, 4CH
INT 21H
MAIN ENDP
END MAIN
I'm using tasm if that helps. I'm about to pull my hair right now too.
来源:https://stackoverflow.com/questions/15398672/nested-loop-in-x86-assembly