NASM:未指定操作大小(NASM: operation size not specified)


NASM:未指定操作大小 - IT屋-程序員軟件開發技術分享社區 (it1352.com)

2020-05-16   IT屋
 

I wrote this code in emu8086 and it goes well in the emulator but when I'm trying to compile it with NASM it's throwing me up the error: "operation size not specified", help someone?

add bx,[3565]
sub bx,0xcc
mov [bx],0CCh
解決方案

NASM can't figure out what you meant by a line like mov [bx],0CCh. Clearly, this sets something to 0CCh. But do you want to have bx pointing to a single byte , short, long, ...? This will manifest itself as the fairly self-explanatory error: operation size not specified in NASM. You could avoid the error specifying the type, as shown below:

SECTION .text
    global start

start:
    add bx,[3565]
    sub bx,0xcc
    mov byte [bx],0CCh

That'd assemble it ok... of course, don't try to run it as it is, it'll produce EXCEPTION_ACCESS_VIOLATION. Just open it with a debugger and you'll understand why.

 

我在emu8086中編寫了這段代碼,並且在模擬器中運行得很好,但是當我嘗試使用NASM進行編譯時,它拋出了錯誤消息:"未指定操作大小",請幫助某人?



 添加bx,[3565] 
sub bx,0xcc
mov [bx],0CCh

解決方案
 

NASM無法弄清這樣的行是什么意思mov [bx],0CCh 。顯然,
會將值設置為0CCh。但是,是否要讓bx指向單個字節
,short,long,...?這將表現為非常明顯的
錯誤:未在NASM中指定操作大小。您可以避免指定類型的錯誤,如下所示:



  SECTION .text 
全局開始

開始:
加bx,[3565]
子bx,0xcc
移動字節[bx],0CCh


可以正常組裝了……當然,不要嘗試按原樣運行它,它會產生 EXCEPTION_ACCESS_VIOLATION 。只需使用調試器打開它,您就會明白為什么。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM