【问题标题】:Invalid combination of opcode and operands [duplicate]操作码和操作数的无效组合[重复]
【发布时间】:2011-07-23 07:52:21
【问题描述】:
SEGMENT .data
    print       db      "%d %d %d %d This is a test of printf", 10, 0
    rowm        dw      160     ;row multiplier
    iterations  db      80      ;number of columns to set

SEGMENT .bss
    offs        resd    1       ;offset 

SEGMENT .text
    attribute   equ     47h ;color attribute

    global _VText
    global _VPage
    extern _vm_buffer
    extern _printf


_VText:

    push ebp
    mov ebp, esp
    push edi
    push esi
    push eax
    push es
    push ecx
    push edx

    mov esi, [ebp+8]        ;message 
    mov es, [_vm_buffer]
    mov dword [offs], 0

    mov ax, [ebp+12]            ;row
    mul dword[rowm]         ;multiply row by 160, result stored in dx:ax
    add [offs], dx          ;add dx:ax to offset
    shl dword [offs], 16
    add [offs], ax

    mov ax, [ebp+16]            ;column
    shl ax, 1               ;multiply column by 2
    add [offs], ax          ;add ax to offset

    mov ax, [ebp+24]            ;page
    shl ax, 12              ;multiply page by 2^12 (4096)
    add [offs], ax          ;add ax to offset   

    mov edi, offs           ;set offset
    mov ah, [ebp+20]        ;attribute

    sub byte[iterations], [ebp+16]   ;so that we don't write too many columns
    mov ecx, iterations

next_char:
    lodsb                   ;get the input string type
    cmp al, 00h             ;check for null character
    je null_ch              ;if null, then quit (null character indicates end of the string)
    stosw                   ;store ax to video memory
    loop next_char          ;will loop 80 times

null_ch:
    pop edx
    pop ecx
    pop es
    pop eax
    pop esi
    pop edi
    pop ebp
    ret


_VPage:



    ret

我之前研究过这个错误,它说添加括号是我这样做的,但它没有修复。

请帮忙。

【问题讨论】:

    标签: assembly opcode operands


    【解决方案1】:

    这是哪个架构,哪个汇编器?对我来说,它看起来像 Intel/NASM-ish 语法中的 i386(但它只是一个小的 sn-p)。错误出现在哪一行代码?在任何情况下你都不能这样做:

    sub byte[iterations], [ebp+16]
    

    您不能直接从内存到内存进行减法。你必须通过一个中间寄存器,例如:

    mov eax, [ebp+16]
    sub byte[iterations], al
    

    但您的错误也可能涉及另一行。

    【讨论】:

    • 你对 nasm 和 intel 的看法也是正确的。但我希望这对完整的代码有进一步的帮助。错误在第 53 行。“sub byte[iterations], [ebp+16]”并且在你更改之后我没有收到错误。如果您不介意检查此代码的其余部分是否存在类似之前的愚蠢错误。
    • 在 x86 中,对于大多数指令,至少有一个操作数需要是寄存器(有一些例外,例如 inc/dec)。您的代码似乎有点“老式” - 'losdb' 和 'stosw' 之类的指令几乎已被弃用,您会发现“mov al, [esi]; add esi,1” 等更快(但在代码大小)。查看 Intel 或 AMD 的优化指南(搜索开发人员网站)。另外,“迭代”只是一个字节是否有原因?作为一个字节而不是双字没有速度优势(它实际上更慢),如果输入> 255,你会换行。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-31
    • 1970-01-01
    • 2013-02-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多