English Amiga Board


Go Back   English Amiga Board > Coders > Coders. General

 
 
Thread Tools
Old 19 February 2011, 22:09   #1
Codetapper
2 contact me: email only!

Codetapper's Avatar
 
Join Date: May 2001
Location: Auckland / New Zealand
Posts: 3,143
Question How do you do a clean base register disassembly using Resource?

I know how most of the functions in the fantastic disassembler Resource work, but I've never worked out how to do this so hopefully someone here knows the answer!

Let's say we have some code like this:

Code:
        lea     _BaseA5(pc),a5
        move.w  #0,2(a5)
        move.l  #'FILE',12(a5)
        move.l  #$10000,16(a5)
        bsr     _Something
        move.l  16(a5),d7
        rts

_BaseA5 dc.w    0
        dc.w    0
        dc.l    0
        dc.l    0
Is it possible to easily put in meaningful symbols throughout the code? Let's say we work out that 2(a5) is the number of retries, and 12(a5) is the name of the file to load.

I would like all the code to change 2(a5) to numRetries(a5), 12(a5) to fileName(a5) etc so the code (everywhere) would look like so:

Code:
        numRetries equ 2
        fileName equ 12
        loadAddress equ 16
 
        lea     _BaseA5(pc),a5
        move.w  #0,numRetries(a5)
        move.l  #'FILE',fileName(a5)
        move.l  #$10000,loadAddress(a5)
        bsr     _Something
        move.l  loadAddress(a5),d7
        rts

_BaseA5 dc.w    0
        dc.w    0
        dc.l    0
        dc.l    0
Is this possible without creating a separate symbol table file and updating it whenever you work something out? I know there is a specify base register function and you can jump down to the _BaseA5 register, set the base to A5, then make it reference that address, but the code looks really messy with symbols created like _LbC00046-DT(a5). You can rename _LbC00046 to be a label but I would prefer a single clean symbol such as fileName to be 2.

Is it possible?
Codetapper is offline  
Old 19 February 2011, 23:47   #2
Psygore
Moderator

Psygore's Avatar
 
Join Date: Jan 2002
Location: France
Posts: 482
It can be done using in menu L (Labels)/Edit single/Symbol - dest (in "Options 1", Symbols must be activated).
But the labels symbols will not be displayed on top in Resource, only when saving the asm file.
Psygore is offline  
Old 20 February 2011, 00:19   #3
Codetapper
2 contact me: email only!

Codetapper's Avatar
 
Join Date: May 2001
Location: Auckland / New Zealand
Posts: 3,143
That only seems to change the current symbol. I was hoping all references to 2(a5) in the code would change.
Codetapper is offline  
Old 20 February 2011, 03:04   #4
Lonewolf10
AMOS Extensions Developer
Lonewolf10's Avatar
 
Join Date: Jun 2007
Location: near Cambridge, UK
Age: 39
Posts: 1,919
Yes, but surely the danger with changing all references to 2(a5) is that it may change some that you don't want changing - for example when a5 contains a different address, unless the program has a way of working out what a5 contains and can compare them all and only change the relevant ones?

Personally, I use DevPac (or any text editor) and would change 2(a5) using the find & replace method.

I hate seeing things like _LbC00046 in dissassembled code. It makes it much harder to understand, IMO. I was tempted to write my own dissassembler at one point, but for now I think I'll stick to just doing it by hand - which is great because I don't need to do it at all with my current project!!


Regards,
Lonewolf10
Lonewolf10 is offline  
Old 20 February 2011, 08:10   #5
Codetapper
2 contact me: email only!

Codetapper's Avatar
 
Join Date: May 2001
Location: Auckland / New Zealand
Posts: 3,143
Well I'm not quite sure how the "specify base register" thing actually works in that case, as if you set a register like a5 to be the base and then set it to use that base register for an address, it does seem to change all code segments throughout the program, whether a5 remains or would change later on!

Maybe it can't be done easily?
Codetapper is offline  
Old 20 February 2011, 09:45   #6
Photon
Moderator
Photon's Avatar
 
Join Date: Nov 2004
Location: Hult / Sweden
Posts: 4,550
There is a liboffset(a6) replacement function, but I have limited experience with that. Unless you can specify a 'stop replacing here' position, it will replace it globally. Glen McDiarmid is obviously a highly intelligent coder, so for lib calls it should be possible; for other uses it's not certain.

Basically, everything that is an offset requires intelligence and manual labor, for search/replace work like this, it's better to do it in a text editor, I think.

My preference (with all of 2 programs resourced so far, haha) is to not analyze what the code does in ReSource, but to just get a working source out with as few steps as possible. Then I bring it into AsmOne and search/replace labels.

Lonewolf, you could do like me and get slightly more readable code, namely search/replace _LbC000xx with Codexx, _LbC00xxx with Codexxx, _LbW000xx with Wordxx etc. (Ie. remove leading zeros and name the label after what is there, usually this gives more insight such as Wordxx label points to longword data, oops)
Photon is offline  
Old 20 February 2011, 12:53   #7
StingRay
move.l #$c0ff33,throat

StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,014
Quote:
Originally Posted by Codetapper View Post
Well I'm not quite sure how the "specify base register" thing actually works in that case, as if you set a register like a5 to be the base and then set it to use that base register for an address, it does seem to change all code segments throughout the program, whether a5 remains or would change later on!

Maybe it can't be done easily?
I use "create single label" after using "Convert (xx,Ax)". It will change all references in the disassembly then.

If you can't be sure that the base register never changes throughout the program you can/should use the "Convert specific EA's" menu, there you can set the base address and then decide if you want to convert an offset or not. It's a lot of work obviously.

If you only need to convert a small block of code, the "set lower/upper limit" functions might be more convenient since you can define where the conversion should start/end that way.

Quote:
Originally Posted by Lonewolf10 View Post
I hate seeing things like _LbC00046 in dissassembled code. It makes it much harder to understand, IMO.
At least ReSource allows you to change label names at will.

Last edited by StingRay; 20 February 2011 at 13:09.
StingRay 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
How to make sense of disassembly? Jonathan Drain Coders. General 1 27 October 2009 22:57
What do you get when you register? Magno Boots project.WHDLoad 4 31 January 2007 12:18
Need a little disassembly/binary edit help mr_a500 Coders. General 5 30 April 2006 21:33
Game Base 64 V2 plasmatron Retrogaming General Discussion 14 03 September 2004 23:02
Base Jumpers CD³² MethodGit request.Old Rare Games 4 22 January 2002 05:32

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 09:32.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2018, vBulletin Solutions Inc.
Page generated in 0.06956 seconds with 15 queries