汇编:[SI + CX] =地址大小的不可能组合 [英] Assembly: [SI + CX] = impossible combination of address sizes
问题描述
因此,今天,我试图为开发中的操作系统创建一个具有以下简单功能的库:在屏幕上打印字符.要使用此功能,我只需要将字符串地址压入堆栈并调用它(字符串必须以0x00字节结尾).下面是该函数的源代码:
So, today I tried to create a library for my in-development OS with one simple function: To print characters on screen. To use this function I simply have to push the string address to the stack and call it (The string must end with a 0x00 byte). Below is the source code of the function:
__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错误:
Anytime I try to assemble the source code the following nasm error appears:
def_os_lib.asm:10:错误:操作码和操作数的无效组合
def_os_lib.asm:10: error: invalid combination of opcode and operands
def_os_lib.asm:11:错误:操作码和操作数的无效组合
def_os_lib.asm:11: error: invalid combination of opcode and operands
def_os_lib.asm:16:错误:操作码和操作数的无效组合
def_os_lib.asm:16: error: invalid combination of opcode and operands
另外,在某些情况下,即当我以ELF格式编译它时,它会提示此错误:
Also, in some cases, that is when I compile it in ELF format, it prompts this error:
def_os_lib.asm:10:错误:地址大小不可能组合
def_os_lib.asm:10: error: impossible combination of address sizes
def_os_lib.asm:11:错误:地址大小不可能组合
def_os_lib.asm:11: error: impossible combination of address sizes
我用于nasm(bin)的命令是:
The command I use for nasm(bin) is:
nasm -f bin def_os_lib.asm
nasm -f bin def_os_lib.asm
我用于nasm(elf64)的命令是:
The command I use for nasm(elf64) is:
nasm -f elf64 def_os_lib.asm
nasm -f elf64 def_os_lib.asm
我刚刚开始组装,就我所知,我正在迈出太大的一步.我只想更深入一点.
I've just started assembly and I know I'm doing a too big step for my knowledge. I just want to go a little bit more in depth.
谢谢大家的帮助.我已经根据您的建议纠正了错误,从而完成了源代码.这是新代码:
Thank you all for your help. I have completed the source code by correcting the mistakes with your suggestions. Here is the new code:
__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
推荐答案
您只能将[BX或BP]与[SI或DI]结合使用;不允许使用AX,DX或CX.
You can only use [BX or BP] in combination with [SI or DI]; AX, DX or CX are not allowed.
您不能按/弹出一个字节,所以POP AL
,因此任何字节大小的参数都将被视为无效.
You can't PUSH/POP a byte so POP AL
so any byte-size argument will be deemed invalid.
这篇关于汇编:[SI + CX] =地址大小的不可能组合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!