使用函数的 C 汇编器

发布于 2024-10-08 22:05:32 字数 274 浏览 0 评论 0原文

大家好, 我正在尝试根据一些指令集用 C 语言设计一个汇编程序。 我想读取包含指令的汇编语言文件。在十六进制文件中,有十六进制数据、整数数据和负整数数据。我需要将该数据转换为 8 位十六进制数据,其中 6 位表示十六进制数据,其余 2 位是操作码。 例如 ; LDC 0x1000 输出:00100000(ldc的操作码是00) 最不发达国家-3; 输出:fffffd00(+3 的 6 位 2 补码)。

我正在尝试 ltoa 将整数转换为十六进制,但它给出字符串作为输出,所以我无法附加 0s 。 请紧急提出建议

HI all,
I am trying to design an assembler in C based on some instruction sets.
I want to read a assembly language file containing instructions. IN the hex file there is hex data, integer data and negative integer data. I need to convert that data into 8 bit hexadecimal data , out of which 6 bit represents hexadecimal data and the remaining 2 bit will be of opcode.
For example ;
ldc 0x1000
output: 00100000 (opcode of ldc is 00)
ldc -3;
output : fffffd00 (6 bit 2s complement of +3).

I am trying ltoa to convert the integer into hexadecimal, but its giving string as output so i am not able to append 0s .
PLease suggest urgentl

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

临走之时 2024-10-15 22:05:33

您似乎将位与半字节混淆了。一个十六进制数字代表 4 位。操作码可以存储 24 位常数,6 个半字节。使用 strtol() 从字符串中读取值并将其左移 8。或者使用操作码。

You seem to confuse bits with nibbles. One hexadecimal digit represents 4 bits. The opcode can store a 24 bit constant, 6 nibbles. Read the value from the string with strtol() and left-shift it by 8. Or with the opcode.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文