gpt4 book ai didi

c - 使用 GCC 的 Nasm 内联汇编

转载 作者:行者123 更新时间:2023-12-01 19:21:26 25 4
gpt4 key购买 nike

在我的项目中,我需要使用内联Assembly,但它必须是Nasm,因为我对GAS不太熟悉。
我的尝试:

void DateAndTime()
{
asm
(.l1: mov al,10 ;Get RTC register A
out RTCaddress,al
in al,RTCdata
test al,0x80 ;Is update in progress?
jne .l1 ; yes, wait

mov al,0 ;Get seconds (00 to 59)
out RTCaddress,al
in al,RTCdata
mov [RTCtimeSecond],al

mov al,0x02 ;Get minutes (00 to 59)
out RTCaddress,al
in al,RTCdata
mov [RTCtimeMinute],al

mov al,0x04 ;Get hours (see notes)
out RTCaddress,al
in al,RTCdata
mov [RTCtimeHour],al

mov al,0x07 ;Get day of month (01 to 31)
out RTCaddress,al
in al,RTCdata
mov [RTCtimeDay],al

mov al,0x08 ;Get month (01 to 12)
out RTCaddress,al
in al,RTCdata
mov [RTCtimeMonth],al

mov al,0x09 ;Get year (00 to 99)
out RTCaddress,al
in al,RTCdata
mov [RTCtimeYear],al

ret);
}

除了使用 Nasm 而不是 GAS 之外,还有什么方法可以做到这一点吗?

我想我需要在编译时添加一个参数。

最佳答案

GCC 使用 AT&T 语法,而 NASM 使用 Intel 语法。

如果您发现需要在两种格式之间手动转换,那么 objdump 和 ndisasm 工具将会非常方便。只需以当前格式进行汇编,以目标格式进行反汇编,然后修复反汇编程序添加的任何机器生成的疯狂内容。

如果您要专门了解 AT&T 语法,那么查看 GDB 中的反汇编而不是使用 objdump 可能会有所帮助。

关于c - 使用 GCC 的 Nasm 内联汇编,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2106334/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com