Nested loop in x86 Assembly? [closed]

混江龙づ霸主 提交于 2020-01-04 06:35:38

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!