English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Asm / Hardware

 
 
Thread Tools
Old 17 March 2022, 22:55   #1
dansalvato
Registered User
 
Join Date: Jun 2009
Location: United States
Posts: 57
Question about NEAR directive in vasm

Hello, I'm new to Amiga ASM and have been exploring options for base-relative addressing. I've taken a liking to the NEAR directive for its implicitness in converting absolute label references into base-relative ones.

The issue I have is that NEAR doesn't seem to support the relative index addressing mode. For example:

Code:
NEAR  a5
XREF _LinkerDB

DATA
SomeStruct:
dcb.l  4

CODE
lea     _LinkerDB,a5

; This works
move.l  SomeStruct+4,d0

; This is identical to the above
move.l SomeStruct+4(a5),d0

; This does not work
move.l (SomeStruct,d1.w),d0

; Directly referencing a5 also does not work
move.l SomeStruct(a5,d1.w),d0

; This works
lea    SomeStruct,a0
move.l (a0,d1.w),d0
I don't know much about the linker, but is this a limitation based on how NEAR interacts with the linker? This isn't an issue when using BASEREG, although I think I understand how BASEREG works differently and is a more "simple" conversion at assemble time. But I figured if vasm can correctly assemble these instructions with indirect addressing, there shouldn't be anything stopping it from doing indirect with index.

Any insight on what I might be missing about NEAR, and if I should just use BASEREG instead? Thanks very much in advance.

Last edited by dansalvato; 18 March 2022 at 02:12.
dansalvato is offline  
Old 18 March 2022, 05:00   #2
dansalvato
Registered User
 
Join Date: Jun 2009
Location: United States
Posts: 57
I think I answered my own question—the index addressing mode only supports an 8-bit offset value, but NEAR (and base-relative addressing in general) works on the premise that a 16-bit offset is available to fetch data relative to the base address. So, it makes sense that you wouldn't be able to combine an index with this addressing mode.
dansalvato is offline  
Old 18 March 2022, 12:40   #3
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,537
Quote:
Originally Posted by Haxxy View Post
I've taken a liking to the NEAR directive for its implicitness in converting absolute label references into base-relative ones.
For anybody who is wondering why the given example doesn't for him, please note that vasm needs either the
-sd
or the
-phxass
option to enable automatic small-data translations. Also, the referenced symbol should be in a small-data section, named "__MERGED".


Quote:
Code:
; Directly referencing a5 also does not work
move.l SomeStruct(a5,d1.w),d0
That's because this is not a typical small-data addressing mode, which usually has the form
(d16,An)
. You can enable small-data for 68020 extended addressing modes with the
-extsd
option, but you still have to explicitely define
SomeStruct
as a 16-bit displacement. For example, these will work and should generate 16-bit small-data relocs (with -extsd):
Code:
        move.l  (SomeStruct.w,a5,d1.w),d0
        move.l  ([SomeStruct.w,a5],d1.w),d0
Quote:
I don't know much about the linker, but is this a limitation based on how NEAR interacts with the linker?
Here it is more an issue of tradition, enforced by the assembler. The linker (at least vlink) could theoretically handle 8-, 16- and 32-bit base-relative relocations. And AmigaDOS defines HUNK_DREL8, HUNK_DREL16 and HUNK_DREL32 for them.

Traditionally, only 16-bit base relative was ever used in Amiga programs. Certainly for a reason. 8-bit leaves you with only a tiny small-data segment of 256 bytes, and there is no
(d8,An)
addressing mode on 68000 anyway. 32-bit gives you no size advantage to absolute addressing and requires 68020.

Quote:
and if I should just use BASEREG instead?
BASEREG is only an option if you don't have to link your object with other objects. It is local.
phx is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Issues with ORG directive (vasm + FS-UAE) Maggot Coders. Asm / Hardware 15 05 September 2023 11:56
Another Vasm question LeCaravage Coders. Asm / Hardware 7 27 January 2021 23:30
vasm basereg example directive mcgeezer Coders. Asm / Hardware 7 18 November 2020 19:58
Vasm “so.” directive Curbie Coders. General 9 09 April 2020 20:55
REPT directive in vasm phx Coders. Asm / Hardware 8 01 October 2014 21:48

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 01:46.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.11188 seconds with 14 queries