簡體   English   中英

匯編:[SI + CX] =地址大小的不可能組合

[英]Assembly: [SI + CX] = impossible combination of address sizes

因此,今天,我試圖為開發中的操作系統創建一個具有以下簡單功能的庫:在屏幕上打印字符。 要使用此功能,我只需要將字符串地址壓入堆棧並調用它(字符串必須以0x00字節結尾)。 下面是該函數的源代碼:

__print:                        ;Print string that is terminated with a 0x00 to screen

__print_prepare:
    pop si                  ;SI Register = String Address
    mov ah, 0x0E                ;0x0E Function = Print Character on screen
    mov bx, 0x0F                ;Background = Black, CharColor = White
    xor cx, cx              ;Counter = 0

__print_check:
    push byte [cx + si]         ;Push character to the stack
    or byte [cx + si], byte [cx + si]   ;Check if the byte equals 0x00
    jz __print_exit             ;If true then exit
    jmp __print_main            ;Else print the character

__print_main:
    pop al                  ;Store the byte in the AL Register
    int 0x10                ;Call interupt 0x10 = BIOS Interupt
    jmp __print_next            ;Continue to next character

__print_next:
    inc cx                  ;Increment CX Register by one for next character = Counter
    jmp __print_check           ;Check authenticity of character

__print_exit:
    ret

每當我嘗試匯編源代碼時,都會出現以下nasm錯誤:

def_os_lib.asm:10:錯誤:操作碼和操作數的無效組合

def_os_lib.asm:11:錯誤:操作碼和操作數的無效組合

def_os_lib.asm:16:錯誤:操作碼和操作數的無效組合

另外,在某些情況下,即當我以ELF格式編譯它時,它會提示此錯誤:

def_os_lib.asm:10:錯誤:地址大小不可能組合

def_os_lib.asm:11:錯誤:地址大小不可能組合

我用於nasm(bin)的命令是:

nasm -f bin def_os_lib.asm

我用於nasm(elf64)的命令是:

nasm -f elf64 def_os_lib.asm

我剛剛開始組裝,就我所知,我正在邁出太大的一步。 我只想更深入一點。

謝謝大家的幫助。 我已根據您的建議糾正錯誤,從而完成了源代碼。 這是新代碼:

__print:                        ;Print string that is terminated with a 0x00 to screen

__print_prepare:
    pop si                  ;SI Register = String Address
    xor bx, bx              ;Counter = 0

__print_check:
    push bx                 ;Save BX
    xor ax, ax              ;AX = 0
    add bx, si              ;BX = Address of the character
    mov al, byte [bx]           ;AL = Character
    pop bx                  ;Restore BX
    push ax                 ;Save character
    or ax, ax               ;Check if the byte equals 0x00
    jz __print_exit             ;If true then exit
    jmp __print_main            ;Else print the character

__print_main:
    pop ax                  ;Store the byte in the AL Register
    push bx                 ;Save BX
    mov bx, 0x0F                ;Background = Black, CharColor = White
    mov ah, 0x0E                ;0x0E Function = Print Character on screen
    int 0x10                ;Call interupt 0x10 = BIOS Interupt
    jmp __print_next            ;Continue to next character

__print_next:
    pop bx                  ;Restore BX
    inc bx                  ;Increment CX Register by one for next character = Counter
    jmp __print_check           ;Check authenticity of character

__print_exit:
    ret

推入字節[cx + si]

cx不能用於實模式下的地址處理

或字節[cx + si],字節[cx + si]

通常在x86中,一條指令中不能有兩個內存操作數。 您需要使用寄存器作為中間人。

您只能將[BX或BP]與[SI或DI]結合使用; 不允許使用AX,DX或CX。

您不能按PU / POP字節,所以不能POP AL因此任何字節大小的參數都將被視為無效。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM