Nat*_*pos 2 c gcc inline nasm inline-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);
}
Run Code Online (Sandbox Code Playgroud)
有什么方法可以做到这一点,但使用Nasm而不是GAS?
我想我需要在编译时添加一个参数.
GCC使用AT&T语法,而NASM使用Intel语法.
如果您发现需要在两种格式之间手动转换,objdump和ndisasm工具将非常方便.只需以当前格式汇编,以目标格式反汇编,然后修复反汇编程序添加的任何机器生成的疯狂.
如果您特意使用AT&T语法,那么在GDB中查看反汇编而不是使用objdump可能会有所帮助.