Author Topic: Converting a A86 operation to NASM  (Read 7057 times)

Offline atl877

  • Jr. Member
  • *
  • Posts: 4
Converting a A86 operation to NASM
« 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?

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Converting a A86 operation to NASM
« Reply #1 on: August 26, 2022, 09:39:58 PM »
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



Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Converting a A86 operation to NASM
« Reply #2 on: August 26, 2022, 09:54:01 PM »
Code: [Select]
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

Offline atl877

  • Jr. Member
  • *
  • Posts: 4
Re: Converting a A86 operation to NASM
« Reply #3 on: August 26, 2022, 11:14:48 PM »
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

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Converting a A86 operation to NASM
« Reply #4 on: August 26, 2022, 11:41:51 PM »
Dunno. Labels in different segments must be the problem, but I don't know how to fix it.

Best,
Frank


Offline atl877

  • Jr. Member
  • *
  • Posts: 4
Re: Converting a A86 operation to NASM
« Reply #5 on: August 27, 2022, 01:52:57 AM »
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

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Converting a A86 operation to NASM
« Reply #6 on: August 27, 2022, 03:32:03 AM »
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


Offline atl877

  • Jr. Member
  • *
  • Posts: 4
Re: Converting a A86 operation to NASM
« Reply #7 on: August 27, 2022, 12:38:20 PM »
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

Offline fredericopissarra

  • Full Member
  • **
  • Posts: 373
  • Country: br
Re: Converting a A86 operation to NASM
« Reply #8 on: August 27, 2022, 01:07:10 PM »
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:

Code: [Select]
  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.