【发布时间】:2014-08-26 02:35:02
【问题描述】:
我在Assembly 中依次访问字符串的每个字符时遇到了一些麻烦。在将'Hello World!', 0 声明到bx 注册表之前,我有以下代码调用print_string 例程:
mov bx, HELLO_MSG
call print_string
HELLO_MSG:
db 'Hello, World!', 0
在print_string 内,我可以通过这样做打印字符串的第一个字符:
mov al, [bx]
; Trigger a single character print
mov ah, 0x0e
int 0x10
在我对汇编的基本理解中,第一个字符 (H) 的地址被保存到 bx,所以通过执行 mov al, [bx],我取消引用指针并将 H 的实际值分配给al.
基于这种理解(如果我错了,请纠正我)我尝试了以下方法:
mov cl, bx ; Move the pointer to `cl`
add cl, 1 ; Do pointer arithmetic to add one byte to the address (hopefully referencing the next character)
mov al, [cl] ; Dereference the address
但是我得到这个错误指向mov al, [cl] 行:
error: invalid effective address
我还尝试了以下方法:
mov al, [bx] ; Move the dereferenced address to `al` (so `al` has `H`)
add al, 1 ; Increment `al`, but of course I'm getting the ASCII value of `H` + 1, which is not the next character in the string.
【问题讨论】: