汇编-程序无法正确退出,而无法放入Debug32.exe

时间:2018-12-08 09:26:20

标签: assembly

我正在用汇编语言编写“十六进制转换程序”,它在调试mod中运行没有问题,但在DOSBox中却没有问题。我检查了SP,没有溢出。我曾尝试过更改ret-> retf,问题仍然存在,有人知道发生了什么吗?我很感激

*我想尝试另一个调试器,但DOSBox不允许我运行它,所以我认为可能是'debug32.exe'问题?由于它是旧版本。 “ MS-DOS版本不正确”

https://github.com/laisiotou1997/ASSEMBLY_practise/raw/master/Tools.zip 工具:

-DEBUG32.EXE

-LINK.EXE

-MASM.EXE

DOSBox 0.74-2

系统:4.15.0-39-generic#42-Ubuntu SMP Tue Oct 23 15:48:01 UTC 2018 x86_64 x86_64 x86_64 GNU / Linux

;/*
;|**********************************************************************;
;* Project           : Hex Conversion_Assembly
;*
;* Program name      : hexToAsc.asm
;*
;* Author            : SIO TOU LAI (laisiotou1997@gmail.com)
;*
;* Date created      : 08/12/2018
;*
;* Purpose           : Change Hex to ASCII than print on screen
;*
;* Revision History  :
;*
;* Date        Author      Ref    Revision (Date in DDMMYYYY format) 
;* 08122018    lst97       1      First release
;*
;* Known Issue       :
;*
;* Program won't exit properly with out put into Debug32.exe
;|**********************************************************************;
;*/

assume cs:code, ds:data, ss:stack

data segment
    db 6 dup(0)
data ends

stack segment
    dw 3 dup(0)
stack ends

code segment
main:   mov ax, data
    mov ds, ax
    mov ax, stack
    mov ss, ax
    mov sp, 0006h
    xor si, si

    mov ax, 12666               ;The number that need to be conver
    mov cx, 0005h
    call HtASC              ;Hex to ASCII

    mov ax, 0B800h
    mov es, ax
    mov si, 18h             ;0 - 24 row
    mov di, 0h              ;0 - 79 word
    mov dx, 0002h               ;Colour code
    xor ax, ax
    xor bx, bx
    call show_str
    mov ax, 4C00h
    int 21h

HtASC:  mov bx, 0Ah
lpA:    div bx
    add dx, 30h
    push bx
    mov bx, cx
    mov ds:[bx - 01h], dl
    dec bx
    pop bx
    xor dx, dx
    loop lpA
    ret

show_str:   mov bx, 00A0h           ;Calculate row length
        mov ax, bx
        mov bx, 10h
        mul si
        div bx
        add ax, 0B800h
        mov es, ax

        mov bx, di          ;Calculate word length
        mov ax, bx
        mov di, 02h
        mul di
        mov bx, ax

        mov di, 00h         ;Initialize
        mov si, 00h
        mov cx, 0005h
        mov dx, 0002h
lpWord:     mov al, ds:[di]         ;Get a word from memory [data segment]
        mov es:[bx + si], al

        mov es:[bx + si + 01h], dl

        inc di
        add si, 02h
        loop lpWord

        mov al, ds:[di + 01h]       ;Won't jmp if not 0 in [data segment]
        mov cx, ax
        jcxz p_end

p_end:      ret

code ends
end main

程序可以在调试模式下退出:

正确的结果:

没有调试模式就无法正确退出:

0 个答案:

没有答案