2016-12-04 4 views
2

그래서 화면의 다른 영역에서 크기가 다른 사각형을 인쇄하는 작업이 있습니다. 각 사각형을 다른 사각형에서 똑같이 멀리 떨어지게하고 싶습니다. u로 볼 수 있듯이 각 사각형 사이의 거리가 항상 감소합니다. 나는 문제가 내가 lengthOFsideAX에를 업데이트 할 때, 변경되지 않는다는 것입니다 생각 My Result:서로 다른 크기의 사각형을 인쇄하십시오.

: 이것은 내 결과입니다. 다른 팁은 많이 주시면 감사합니다 :) 여기에 코드입니다 : lengthOFside 5의 고정 된 값을 가지고 있기 때문에

; 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. 
+4

는 귀하의 의견은 내 눈을 다치게! :) 어쨌든 디버거를 사용하여 코드를 단계별로 실행하고 어디에서 잘못되었는지 확인하십시오. – Jester

+0

@Jester 문제는 소프트웨어에서 디버깅하는 방법을 알아 내지 못합니다. 그리고 그 말은 저에게 상처를줍니다. – user6219654

+1

http://courses.ee.sun.ac.za/OLD/2003/Rekenaarstelsels245/8086_Instruksies/emulator.html – Ped7g

답변

3
ADD BH,lengthOFside+2 ; move right lengthOFside times. 

이 항상 오른쪽으로 동일한 금액을 이동!
AX 레지스터에있는 쪽의 현재 길이로 또한 상대를 확인하십시오

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

짧은은 :

add  ax, 2 
add  bh, al 
+0

그러나이 솔루션은 128 개의 첫 번째 사각형에 대해서만 유효합니다. 왜냐하면'AX' 레지스터의 하위 8 비트 인 – user6219654

+2

@ user6219654를 취할 것이기 때문에 얼마나 많은 사각형을 생성 할 것으로 예상합니까? 화면 크기를 고려하지 않습니까? 이 정답은 각 정사각형 사이에 적절한 간격을 제공하기 때문에 ** ** 정확합니다. 따라서 확인란을 선택하여 확인하십시오. –

+0

나는 그것이 틀렸다는 것을 말하지 않았다. 나는 그것을 올바르게 이해했는지 이해하려고 노력하고있다. – user6219654