assembly - 如何使用标签和寄存器作为偏移量从内存复制到寄存器中?
问题描述
我正在尝试创建一个 print_hex 函数,它将寄存器 bx 中的十六进制值转换为字符数组,我正在努力理解为什么 nasm 告诉我我有一个无效的有效地址。我的 print_hex 函数如下所示:
print_hex:
pusha
; shift counter
mov ax, 12
ph_loop:
; if bx is 0 just print the predefined "0000" on hex_buff
test bx, bx
jz ph_loop_end
mov cx, bx
; mask cx to have only the first character
and cx, 0x000F
; use cx as the offset in the table and bring the character into cx (this is where the compile error happens)
mov cx, [hex_table + cx]
; copy into a buffer the character that i just brought (using cl because for some reason if I use cl it copies 2 characters from the table)
mov [hex_buff], cl
shr bx, ax
; decrement counter by 4
sub ax, 4
jmp ph_loop
ph_loop_end:
mov bx, hex_buff
call print_string
popa
ret
更多信息,这是作为引导扇区程序运行的。我已经阅读了几篇关于使用 lea 的文章,但我不确定我是否可以在这里使用它。
解决方案
推荐阅读
- pandas - pandas grouby 根据多个条件对日期时间列进行计数
- javascript - 自动完成中的 React Material UI 打开模式失去焦点
- java - 此查询中的 sql 语法错误是什么?
- c - 如何使用 GResource 在 Gtk3 中加载图标
- c# - 使用泛型 C# 使用 where 子句进行选择
- php - TDD:模拟对象堆栈的最佳实践
- mysql - 在查询构建器中实现 SQL 时出现问题
- laravel - 使用 Vue.Js / Inertia.js 和 Laravel 对结果进行分页
- r - R:每行创建数据框行,其中包含命名列和类型列
- docker - 多阶段 Docker 映像