NASM - The Netwide Assembler

NASM Forum => Programming with NASM => Topic started by: radlyeel on September 01, 2022, 09:14:47 PM

Title: How to modify value of symbol?
Post by: radlyeel on September 01, 2022, 09:14:47 PM
Does NASM have something like as's .SET, which changes the value of a symbol?  I *thought* %assign would be my friend, but alas, I was wrong yet again  It would be useful to build a linked list, like this:

Code: [Select]
default rel   
%assign lnk 0
%macro node 3 ; usage: node "name". 4, 7
    db %2     ; insert name length
    db %1     ; insert name
    align 8, db 0 ; pad 0s to 8-byte boundary
    dq %3     ; store value
    dq lnk        ; store link to preceding node
    %assign lnk $-16 ; set new value of link for next node
%endmacro

; satisfy NASM, ld, an lldb for examining results
global _main
_main: jmp $
node "OUN",2, 1
node "TROIS",5,3

With that, I get this:
Code: [Select]
$ nasm -g -f macho64 -o demo.o demo.s
demo.s:15: error: non-constant value given to `%assign'
demo.s:9: ... from macro `node' defined here
demo.s:16: error: non-constant value given to `%assign'
demo.s:9: ... from macro `node' defined here
Title: Re: How to modify value of symbol?
Post by: debs3759 on September 02, 2022, 12:35:33 AM
If you use %define instead of %assign, it assembles. Reading the manual, I believe it acts the same, but accepts memory addresses as part of the macro.
Title: Re: How to modify value of symbol?
Post by: Frank Kotler on September 02, 2022, 03:07:22 AM
Is this any help?

https://forum.nasm.us/index.php?topic=1769.

Best,
Frank

Title: Re: How to modify value of symbol?
Post by: Wilford81J on January 10, 2023, 08:37:48 AM
Is this any help?

https://forum.nasm.us/index.php?topic=1769./myccpay (https://www.myccpay.me/)

Best,
Frank
Hello, Frank Kotler
I also have this same question and I cannot find any proper answers, But today i was find my solution is here.


Thanks,