本文介绍了为什么我的代码在添加 .386 时不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题中所解释的,我需要让这段代码能够做与仅使用 16 位相同的事情,但将 .386 添加到代码中,以便我可以使用 32 位寄存器.但是当我现在添加 .386 时,我的代码没有打印任何内容,不知道如何解决这个问题.我的 mov 有问题吗,@data 还是我需要添加其他东西?我正在使用 TASM

As explained in the title, I need to make this code able to do the same things it do using just 16bit but adding .386 to the code so I can use 32bit registers. But when I add the .386 now my code isn't printing anything, any idea how I can fix this. Is it something wrong with my mov as, @data or do I need to add something else? I am using TASM

TITLE Programa de prueba(prueba.asm)
.386
.model small
.stack

.data

escoga db 10,13,7, 'Escoga la operacion: 1. x and y, 2. x or y, 3. not x, 4. x xor y, 5. terminar:
', '$'

digite1 db 10,13,7, 'Digite el primer numero hexadecimal: ', '$'
digite2 db 10,13,7, 'Digite el segundo numero hexadecimal: ', '$'
Yval db "Enter Y hexadecimal value: ",0
resultStr db "The result is: ",0
result db ?
x db 8 DUP(' '),'$'
y db 8 DUP(' '),'$'
num db 1 DUP(0),'$'

.code
main proc
    mov ax, @data
    mov ds, ax

.loop1:
    cmp si, 82
    je .done1
    mov ah, 0Eh
    mov al, escoga[SI]
    mov bh, 00h
    int 10h
    inc si
    jmp .loop1

.done1:
    mov si, 0
    mov di, 0
.inp1:
    cmp si, 1
    je .ext1
    mov ah, 00h
    int 16h
    inc si
    inc di
    jmp .modi1

.modi1:
    mov num[di], al
    mov ah, 0Eh
    mov al, num[di]
    mov bh, 00h
    int 10h
    jmp .inp1

.ext1:
    mov si, 0
.ext2:
    cmp si, 2
    je .salir
    mov ah, 0Eh
    mov al, num[SI]
    inc si
    jmp .ext2

.salir:
    cmp num[SI-1], '5'
    jge .term
    jmp .term2

.term2:
    mov si, 0

.loop2:
    cmp si, 40
    je .done2
    mov ah, 0Eh
    mov al, digite1[SI]
    mov bh, 00h
    int 10h
    inc si
    jmp .loop2

.done2:
    mov si, 0
    mov di, 0

.inp2:
    cmp si, 8
    je .ext3
    mov ah, 00h
    int 16h
    inc si
    inc di
    jmp .modi2

.modi2:
    mov x[di], al
    mov ah, 0Eh
    mov al, x[di]
    mov bh, 00h
    int 10h
    jmp .inp2

.ext3:
    mov si, 0
    mov di, 0

.loop3:
    cmp si, 41
    je .done3
    mov ah, 0Eh
    mov al, digite2[SI]
    mov bh, 00h
    int 10h
    inc si
    jmp .loop3

.done3:
    mov si, 0
    mov di, 0

.inp3:
    cmp si, 8
    je .ext4
    mov ah, 00h
    int 16h
    inc si
    inc di
    jmp .modi3

.modi3:
    mov y[di], al
    mov ah, 0Eh
    mov al, y[di]
    mov bh, 00h
    int 10h
    jmp .inp3

.ext4:
    mov si, 0
    mov di, 0

.term:
.exit

main endp

end main

推荐答案

MASM 6.1 文档是编写实模式分段代码(非 FLAT 模型)的好资源.即使您使用的是 TASM,MASM 文档仍然是一个很好的参考.您遇到的是一种相当微妙的方式的副作用,其中代码生成方式取决于 where 您将 .386 指令相对于 .MODEL 指令.这种微妙的行为记录在设置段字大小(仅限 80386/486)部分:

The MASM 6.1 documentation is a good resource for writing real-mode segmented code (non-FLAT models). Even though you are using TASM, the MASM documentation is still a good reference. What you are encountering is a side effect of a rather subtle way in which code is generated depending on where you place the .386 directive relative to the .MODEL directive. This subtle behaviour is documented in the section Setting Segment Word Sizes (80386/486 Only):

设置段字大小(仅限 80386/486)

SEGMENT 指令中的 use type 指定了段字长在 80386/486 处理器上.段字长决定默认值段中所有项的操作数和地址大小.尺寸属性可以是 USE16、USE32 或 FLAT.如果您指定 .386 或 .486.MODEL 指令之前的指令,USE32 是默认值.这个属性指定段中的项目使用32 位偏移而不是 16 位偏移.如果 .MODEL 在 .386 之前或 .486 指令,USE16 是默认值. 要使 USE32 成为默认值,将 .386 或 .486 放在 .MODEL 之前.您可以覆盖 USE32 默认值使用 USE16 属性,反之亦然.

The use type in the SEGMENT directive specifies the segment word sizeon the 80386/486 processors. Segment word size determines the defaultoperand and address size of all items in a segment. The size attributecan be USE16, USE32, or FLAT. If you specify the .386 or .486directive before the .MODEL directive, USE32 is the default. Thisattribute specifies that items in the segment are addressed with a32-bit offset rather than a 16-bit offset. If .MODEL precedes the .386or .486 directive, USE16 is the default. To make USE32 the default,put .386 or .486 before .MODEL. You can override the USE32 defaultwith the USE16 attribute, or vice versa.

您需要注意的是放置 .386 的位置.您已将它放在 .model 之前,因此汇编程序假定所有部分默认为 USE32.这意味着正在生成的所有指令都是在假设处理器以 32 位模式运行的情况下进行编码的.32 位编码指令无法在 16 位代码中正常运行,并且是导致程序失败的原因.

What you need to be careful about is where you place .386. You have placed it before .model thus the assembler is assuming that all the sections are USE32 by default. This means all the instructions that are being generated are encoded with the assumption the processor is running in 32-bit mode. 32-bit encoded instruction do not run properly in 16-bit code and is the cause of your program failure.

您正在编写将在 16 位实模式下运行的代码(可能使用 386 条指令和寄存器),因此我相信您会希望在使用 时确保 USE16 是默认值.code.data 指令.要获得您想要的行为,您必须进行此更改:

You are writing code that will run in 16-bit real-mode (possibly using 386 instructions and registers) so I believe you will want to ensure USE16 is the default when using the .code and .data directives. To get the behaviour you want you have to make this change:

.386
.model small

致:

.model small
.386

这篇关于为什么我的代码在添加 .386 时不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 02:19