操作码和操作数的组合无效

时间:2011-03-26 01:49:00

标签: assembly opcode operands

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

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

请帮忙。

1 个答案:

答案 0 :(得分:3)

这是哪个架构,哪个汇编程序?看起来i386采用Intel / NASM-ish语法(但它只是一个小片段)。哪一行代码是错误的?无论如何你不能这样做:

sub byte[iterations], [ebp+16]

你无法直接从内存中减去内存。您必须通过中间寄存器,例如:

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

但你的错误可能也指另一条线。