相邻打印不同大小的正方形

Printing squares in difference size next to each other

所以我的任务是在屏幕的不同区域打印不同大小的正方形。我希望每个方块与另一个方块的距离相等。如您所见,每个方块之间的距离总是减小。这是我的结果:

我认为问题是当我将 lengthOFside 更新为 AX 时,它没有改变。任何其他提示将不胜感激:)这是代码:

; multi-segment executable file template.     

newline=160 ;number of chars to move to next line 
col = 2     ;each column is another charachter
lengthOFside = 5 ;side of square, grows each time of the loop
numRow = 5 ;which row to start from
numCol = 30 ;which col to start from
numSquares = 4 ;number of squares


data segment
    ; add your data here!
    pkey db "press any key...$"
ends

stack segment
    dw   128  dup(0)
ends

code segment
start:
; set segment registers:
    mov ax, data
    mov ds, ax
    mov AX,0B800H
    MOV ES,AX



    ; add your code here  

    ;first print


    MOV DH, numSquares     ;number of squares I want to print
    MOV AX,lengthOFside       
    MOV BL,numRow   ;number line
    MOV BH,numCol   ;num col   
    MOV CX,lengthOFside ;length of one side
    CALL print_square   ;CALL the function that prints the square
    DEC DH


    loopPrint:
    lengthOFside = ax
    ADD BH,lengthOFside+2 ; move right lengthOFside times. 
    ADD AX,2
    MOV CX,AX
    CALL print_square ;print square

    DEC DH
    jnz loopPrint





    lea dx, pkey
    mov ah, 9
    int 21h        ; output string at ds:dx

    ; wait for any key....    
    mov ah, 1
    int 21h

    mov ax, 4c00h ; exit to operating system.
    int 21h 

    print_square: ;get (x,y) as (bh,bl) and cx = length of one side. Prints a square from that point.                

        MOV SI,0 

        PUSH BX
        CALL Get2startpoint ;get to starting point
        POP BX

        PUSH CX
        CALL  Horizontal_Line  ;print the first horizontal line
        POP CX

        PUSH CX  
        CALL Vertical_Line  ;print the first vertical line
        POP CX  


        PUSH BX
        CALL Get2startpoint   ;return to starting point
        POP BX


        PUSH CX  
        call Vertical_Line    ;print another vertical line
        POP CX  

        PUSH CX
        SUB SI,newline  ;we do because the function vertical line adds new line every END of it's loop. 
                        ;So SI is on the next line so the vertical line will be n+1. so we decrease one line from si
        CALL Horizontal_Line   ;print anohter horizontal line
        POP CX

    RET



    Vertical_Line: 
        ADD SI,newline        ;prints vertical line adds to si 160 after printing *
        DEC CX                ;prints vertical line adds to si 160 after printing *
        LOOP2:                ;prints vertical line adds to si 160 after printing *
        MOV ES:[SI],'*'       ;prints vertical line adds to si 160 after printing *
        ADD si,newline        ;prints vertical line adds to si 160 after printing *
        LOOP LOOP2            ;prints vertical line adds to si 160 after printing *
    RET

    Horizontal_Line:          ;add si,2 to get to the next data cell and insert * 
        MOV ES:[SI],'*'       ;add si,2 to get to the next data cell and insert * 
        DEC CX                ;add si,2 to get to the next data cell and insert * 
        LOOP1:                ;add si,2 to get to the next data cell and insert * 
        ADD SI,2              ;add si,2 to get to the next data cell and insert * 
        MOV ES:[SI],'*'       ;add si,2 to get to the next data cell and insert * 
        LOOP LOOP1            ;add si,2 to get to the next data cell and insert * 
    RET    

    Get2startpoint:             ;gets (x,y) as <bh,bl> and gets to the point where it should start printing the square
        MOV SI,0                ;gets (x,y) as <bh,bl> and gets to the point where it should start printing the square
        ADD_NEW_LINE:           ;gets (x,y) as <bh,bl> and gets to the point where it should start printing the square
        ADD SI,newline          ;gets (x,y) as <bh,bl> and gets to the point where it should start printing the square
        DEC BL                  ;gets (x,y) as <bh,bl> and gets to the point where it should start printing the square
        JNZ ADD_NEW_LINE        ;gets (x,y) as <bh,bl> and gets to the point where it should start printing the square
                                ;gets (x,y) as <bh,bl> and gets to the point where it should start printing the square
        SKIP_TO_COL:            ;gets (x,y) as <bh,bl> and gets to the point where it should start printing the square
        ADD SI,col              ;gets (x,y) as <bh,bl> and gets to the point where it should start printing the square
        DEC BH                  ;gets (x,y) as <bh,bl> and gets to the point where it should start printing the square
        JNZ SKIP_TO_COL         ;gets (x,y) as <bh,bl> and gets to the point where it should start printing the square
    RET        








ends

end start ; set entry point and stop the assembler.
ADD BH,lengthOFside+2 ; move right lengthOFside times.

这总是向右移动相同的量,因为 lengthOFside 的固定值为 5!
相对于 AX 寄存器中边的 当前 长度进行添加:

add     bh, al
add     bh, 2
add     ax, 2

更短:

add     ax, 2
add     bh, al