[SOLVED] What's the proper way to define macro in YASM?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
Roman
Member
Member
Posts: 568
Joined: Thu Mar 27, 2014 3:57 am
Location: Moscow, Russia
Contact:

[SOLVED] What's the proper way to define macro in YASM?

Post by Roman »

That's my macro for halting the CPU:

Code: Select all

%macro cpu_halt 0
        cli
        hlt
%endmacro
And when I call it nothing happens:

Code: Select all

cpu_halt
Code compiles without any warning, but CPU doesn't halt.
Last edited by Roman on Sat Aug 16, 2014 5:12 am, edited 1 time in total.
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay
User avatar
iansjack
Member
Member
Posts: 4709
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: What's the proper way to define macro in YASM?

Post by iansjack »

So, what does the assembled code look like?
User avatar
Roman
Member
Member
Posts: 568
Joined: Thu Mar 27, 2014 3:57 am
Location: Moscow, Russia
Contact:

Re: What's the proper way to define macro in YASM?

Post by Roman »

iansjack wrote:So, what does the assembled code look like?
I added this to check.

Code: Select all

        mov ax, [blah]
        cli
        hlt

...
...
...

blah:
        cpu_halt

AX == 4dbe

It's strange, because CLI & HLT should be 0xFA & 0xF4.
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: What's the proper way to define macro in YASM?

Post by Combuster »

yasm manual wrote: -Worphan-labels: Warn on labels lacking a trailing option
When using the NASM-compatible parser, causes Yasm to warn about labels found alone on a line without a trailing colon. While these are legal labels in NASM syntax, they may be unintentional, due to
typos or macro definition ordering.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
alexfru
Member
Member
Posts: 1112
Joined: Tue Mar 04, 2014 5:27 am

Re: What's the proper way to define macro in YASM?

Post by alexfru »

"mov ax, [blah]" might probably need to be changed to something like "mov ax, cs:[blah]". At any rate, YASM should be able to generate a listing file, in which you should find the actual instructions from the expanded macros and/or instruction opcodes. Besides, there are disassemblers out there! I don't know if YASM comes with one, but NASM does.
User avatar
Roman
Member
Member
Posts: 568
Joined: Thu Mar 27, 2014 3:57 am
Location: Moscow, Russia
Contact:

Re: What's the proper way to define macro in YASM?

Post by Roman »

Moved the macro to the top of the code, now works.
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay
Post Reply