NASM - The Netwide Assembler
NASM Forum => Programming with NASM => Topic started by: atl877 on August 26, 2022, 08:36:36 PM
-
I successfully converted a86 code to NASM with the following exception:
REGDIF equ (offset AXSAVE) - (offset REGTAB)
where AXSAVE and REGTAB are labels (locations). I am clear that NASM does not need the OFFSET prefix so got rid of that first.
I'ver tried every combination I know of but cannot get this to go through. I get the same error: invalid opcode type. Casting the two addresses as "WORD" does not help.
Is there some documentation I can access to help me figure this out?
-
Hi atl887,
Welcome to the forum.
Nasm does have a Friendly Manual of course, but it may not help you with this. There's something a little strange about "invalid opcode type": I don't see an opcode... or anything Nasm would think was an opcode. Do you get this error from the expression you show, or where you try to use it?
You may need to show us more of your code before we can figure this out.
Best,
Frank
-
bits 16
REGTAB:
nop
nop
AXSAVE:
REGDIF equ AXSAVE - REGTAB
mov ax, REGDIF
This works for me. What did I miss?
Best,
Frank
[ Read 11 lines ]
^G Get Help ^O Write Out ^W Where Is ^K Cut Text ^J Justify
^X Exit ^R Read File ^\ Replace ^U Paste Text ^T To Spell
-
Thank you for the prompt response. Here is a bit more context:
AXSAVE resw 1
BXSAVE resw 1
.
.
REGTAB db 'abc....'
REGDIF equ AXSAVE - REGTAB
.
.
.
AXSAVE is in seg 0000h (low RAM)
REGTAB is in seg FE00h
This code is part of a monitor to reside in EPROM.
atl
-
Dunno. Labels in different segments must be the problem, but I don't know how to fix it.
Best,
Frank
-
Thanks again. Since this is (simply) address arithmetic, I suspect there is something I am missing. A86 didn't seem to care about different segments when doing offset math. For now, I will just "hard code" the value.
atl
-
Okay, if you can hard-code the value, perhaps that's best.
I am puzzled, though. Since A86 is doing "offset minus offset", the distance between segments may not being considered. I wonder why this value is useful? If the distance between segments is calculated, it will be a large value, and perhaps hard to use?
Your code - I don't need to understand it. But if you feel like chatting, enlighten me, if possible...
Best,
Frank
-
Frank,
This is a good question. It's actually not my code. I am resurrecting a Lomas Data Thunder 186. There is an "updated" monitor ROM I am trying to implement. This might have been part of a long lost trick. Your advice is well taken: study the code and figure out what needs to be done.
atl
-
It makes no sense calculating the difference of offsets in different segments. Consider your AXSAVE is at offset 0 of segment 0 and REGTAB is at offset 2 of segment 0xfe00. This way REGDIF will be a negative value (AXSAVE - REGTAB = 0 - 2 = -2 or 0xfffe). And this isn't the distance between the labels, since the physical address, based on logical ones are, for AXSAVE, 0x00000, and REGDIF, 0xfe002. Even if you use the physical addresses and calculate REGDIF - AXSAVE instead, you'll get 0xfe002 or 1040386, instead of 0xfffe or 65534.
That's why NASM don't allow this:
bits 16
section _data1
a: db 0
section _data2
b: db 0
_diff equ b - a ; ERROR
First, there is the problem mantioned earlier. And there is another: _data1 and _data2 aren't, necessarily, sequential (the linker will arrange it the way it wants)... There is no way NASM knows if a comes first or not.