Author Topic: How to modify value of symbol?  (Read 9052 times)

Offline radlyeel

  • New Member
  • Posts: 1
How to modify value of symbol?
« 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

Offline debs3759

  • Global Moderator
  • Full Member
  • *****
  • Posts: 224
  • Country: gb
    • GPUZoo
Re: How to modify value of symbol?
« Reply #1 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.
« Last Edit: September 02, 2022, 12:42:31 AM by debs3759 »
My graphics card database: www.gpuzoo.com

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: How to modify value of symbol?
« Reply #2 on: September 02, 2022, 03:07:22 AM »
Is this any help?

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

Best,
Frank


Offline Wilford81J

  • Jr. Member
  • *
  • Posts: 10
Re: How to modify value of symbol?
« Reply #3 on: January 10, 2023, 08:37:48 AM »
Is this any help?

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

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,
« Last Edit: January 11, 2023, 04:21:02 AM by Wilford81J »