2013-03-11 2 views
0

그래서 9보다 큰 숫자를 쓰는 작은 프로그램을 작성했습니다. 하지만 스택에 값을 넣 자마자 스택이 비게 될 때까지는 인쇄 할 수 없습니다. 이 문제를 해결할 방법이 있습니까? 코드에서이 버그가 있습니다어셈블리에서 스택 오류 8086 (리얼 모드) (스택이 가득 차있을 때 문자 인쇄)

print_int:   ; Breaks number in ax register to print it 
    mov cx, 10 
    mov bx, 0 
    break_num_to_pics: 
     cmp ax, 0 
     je print_all_pics 
     div cx 
     push dx 
     inc bx 
     jmp break_num_to_pics 
    print_all_pics: 
     cmp bx, 0  ; tests if bx is already null 
     je f_end 
     pop ax 
     add ax, 30h 
     call print_char 
     dec bx 
     jmp print_all_pics 

print_char:    ; Function to print single character to  screen 
     mov ah, 0eh  ; Prepare registers to print the character 
     int 10h   ; Call BIOS interrupt 
     ret 

f_end:    ; Return back upon function completion 
    ret 

답변

0

: 여기

는 코드입니다.

print_int:   ; Breaks number in ax register to print it 
    mov cx, 10 
    mov bx, 0 
    break_num_to_pics: 
    cmp ax, 0 
    je print_all_pics 

    ; here you need to zero dx, eg. xor dx,dx 

    xor dx,dx  ; add this line to your code. 

    div cx   ; dx:ax/cx, quotient in ax, remainder in dx. 
    push dx   ; push remainder into stack. 
    inc bx   ; increment counter. 
    jmp break_num_to_pics 

문제는 당신이 분할 전에하지 제로 dx을 할 것입니다 : 첫 번째는

은하지 제로 dxdiv cx 전에 할 것입니다. 처음으로 div cx, dx은 초기화되지 않습니다. 다음 번에 div cx에 도달하면 remainder:quotient10으로 나눠지며별로 의미가 없습니다.

다른 하나는 여기에 있습니다 :

print_char:   ; Function to print single character to  screen 
    mov ah, 0eh  ; Prepare registers to print the character 
    int 10h   ; Call BIOS interrupt 
    ret 

당신은 int 10h

INT 10 - VIDEO - TELETYPE OUTPUT 
    AH = 0Eh 
    AL = character to write 
    BH = page number 
    BL = foreground color (graphics modes only) 
( Ralf Brown's Interrupt List 참조) 사람들은 mov ah,0eh의 입력 레지스터가있는 경우에도, blbh에 의미있는 값을 설정하지

bx을 카운터로 사용하기 때문에 print_char 내부 또는 외부에 저장해야합니다. 예를 들어 bx을 저장하면 print_char :

+0

감사합니다. 오늘 나중에 이것을 시도 할 것입니다. 나는 dx에 대해 알아 봤지만 일단 역방향으로 값을 출력하려고 시도했다면 (그래서 9573은 3759가된다. print_int 함수가 필요한 것을 달성 할 것이므로), bx에 대해 몰랐다. 고마워. – ArdentAngel

+0

예, 완벽하게 작동했습니다. 고맙습니다. – ArdentAngel

관련 문제