English Amiga Board


Go Back   English Amiga Board > Support > support.Other

 
 
Thread Tools
Old 16 April 2016, 23:16   #1
Sim085
Registered User
 
Join Date: Apr 2009
Location: Lija
Posts: 463
ReSource - How to re-load ASM file?

Hello, I am experimenting with ReSource. I have opened a binary using the "P > Open binary file" option. I then saved the ASM using the "SV > Save .asm" option. However I have no idea how to re-load the ASM file once edited.

Also is there a way how to edit a line directly from ReSource? Or add additional lines?
Sim085 is offline  
Old 16 April 2016, 23:40   #2
mark_k
Registered User
 
Join Date: Aug 2004
Location:
Posts: 2,966
You can't load an assembly language source file into ReSource. (Well, not without assembling it and loading the resulting executable...)

If you're wanting to save a work-in-progress disassembly, use the "Save .RS" menu item. Then load that .rs file into ReSource and continue your work later.
mark_k is offline  
Old 17 April 2016, 00:03   #3
Sim085
Registered User
 
Join Date: Apr 2009
Location: Lija
Posts: 463
Quote:
Originally Posted by mark_k View Post
If you're wanting to save a work-in-progress disassembly, use the "Save .RS" menu item. Then load that .rs file into ReSource and continue your work later.
Thanks. Would you know how I can edit a line in ReSource? I found out how to rename and create labels and how to add comments. However I cannot find how to edit a line.

For example if I have a line "MOVE.L D1,(A0)" and I want to change it to "MOVE.B (A1)+,D1". How can that be done?
Sim085 is offline  
Old 17 April 2016, 00:08   #4
mark_k
Registered User
 
Join Date: Aug 2004
Location:
Posts: 2,966
If you mean basically binary-patching the file (or at least, the in-memory version that ReSource is working on), look in the * (SPECIAL FUNCTIONS) menu. ZAP->Zap2 could/should do what you want.
mark_k is offline  
Old 17 April 2016, 00:17   #5
Sim085
Registered User
 
Join Date: Apr 2009
Location: Lija
Posts: 463
Quote:
Originally Posted by mark_k View Post
If you mean basically binary-patching the file (or at least, the in-memory version that ReSource is working on), look in the * (SPECIAL FUNCTIONS) menu. ZAP->Zap2 could/should do what you want.
Thanks I was looking under each menu and selecting options but must admit I would have never thought of ZAP.

Many thanks for your help.
Sim085 is offline  
Old 19 April 2016, 21:53   #6
Sim085
Registered User
 
Join Date: Apr 2009
Location: Lija
Posts: 463
Quote:
Originally Posted by mark_k View Post
* (SPECIAL FUNCTIONS) menu. ZAP->Zap2
How do I add a new command with ReSource?

I went through the manual. I read that to add an empty line I had to LABELS > Create Single > Full-Line Comment and enter ";" as comment. I then tried to go to Special Functions > Zap > Zap2. However this shows me the next line command. If I try Zap instead of Zap2 I get a blank box but whatever I enter gets refused.

Last edited by Sim085; 19 April 2016 at 22:49.
Sim085 is offline  
Old 19 April 2016, 22:57   #7
mark_k
Registered User
 
Join Date: Aug 2004
Location:
Posts: 2,966
You can enter a full-line comment with an assembly language opcode. Begin it with a ; to tell ReSource to not put a semicolon on that line in its dissassembly.

For example if you enter this as a full-line comment:
; MOVEQ #0,D0
then in the disassembly (and .asm output) there will be
MOVEQ #0,D0
which will of course, if you run an assembler on the .asm file, produce an executable with that extra instruction in.

However comments like that are still comments as far as ReSource is concerned, i.e. just text. The disassembler doesn't "understand" it as an instruction.

The Zap/Zap2 commands are used to patch (overwrite) bytes of code with different bytes/instructions of your choice. You can't make extra space and put new instructions in there, other than by the full-line comment method.
mark_k is offline  
Old 19 April 2016, 23:25   #8
Sim085
Registered User
 
Join Date: Apr 2009
Location: Lija
Posts: 463
So I am doing as you say, i.e. - when I add the full line comment I enter the following:

"\tMOVEA.L\tD0,D2"

I then use the option SV > Save Executable. I then load the executable again (P > Open Load File). However the command I added as a comment is not there.

So I guess the only option is to save as .asm and then use an assembler to re-assemble and only after that disassemble with Resource.

Off to search for an assembler...


Quote:
Originally Posted by mark_k View Post
However comments like that are still comments as far as ReSource is concerned, i.e. just text. The disassembler doesn't "understand" it as an instruction.
Sim085 is offline  
Old 19 April 2016, 23:47   #9
mark_k
Registered User
 
Join Date: Aug 2004
Location:
Posts: 2,966
I'm not sure exactly what you're trying to do, but is it definitely not possible to patch/change existing instructions, instead of adding new ones? Sometimes, especially if the program you're disassembling was written in C, you can free up a few bytes of space by modifying/adjusting a few instructions to be shorter.

For example, if there is MOVEA.L (4).L,A6 you could patch that to MOVEA.L (4).W,A6 to save two bytes. Or MOVE.L #0,D0 --> MOVEQ #0,D0 to save four bytes.

Getting a disassembly to the state where reassembling the .asm file produces a working executable can be quite a long process. For example, if there are any jump tables which you didn't disassemble correctly, your reassembled executable will most likely break/crash.
mark_k is offline  
Old 20 April 2016, 19:22   #10
Sim085
Registered User
 
Join Date: Apr 2009
Location: Lija
Posts: 463
So after reading this yesterday I decided that the best approach to go through the program little by little and understand what each line is doing.

That said I have found some commands which I do not understand what they mean;

Example (not in that order):

Code:
Output.MSG    db    'Out',0,0
lbL001666    dl    $1F0E201C
    dw    $B20
I looked in the 68000 manuals on line but couldn't find these. On the internet I found these in some x86 examples. I know Output.MSG and lbL001666 are labels but cannot find what db, dl and dw mean. I also tried these in ASM-One but it complains.

Does anyone know what these are?

Quote:
Originally Posted by mark_k View Post
Getting a disassembly to the state where reassembling the .asm file produces a working executable can be quite a long process.
Sim085 is offline  
Old 20 April 2016, 19:29   #11
Galahad/FLT
Going nowhere

Galahad/FLT's Avatar
 
Join Date: Oct 2001
Location: United Kingdom
Age: 45
Posts: 7,070
Db is data byte. Dw is data word and dl is data long

In devpac it would be dc.b, dc.w and dc.l

In asm one it would be blk.b, blk.w and blk.l
Galahad/FLT is offline  
Old 20 April 2016, 20:01   #12
Sim085
Registered User
 
Join Date: Apr 2009
Location: Lija
Posts: 463
How come these instructions are different from one editor to another? and how come these instructions are not in the 68000 manuals?

(btw ... asm one accepted dc.b)

Quote:
Originally Posted by Galahad/FLT View Post
Db is data byte. Dw is data word and dl is data long

In devpac it would be dc.b, dc.w and dc.l

In asm one it would be blk.b, blk.w and blk.l

Last edited by Sim085; 20 April 2016 at 21:27.
Sim085 is offline  
Old 20 April 2016, 21:29   #13
mark_k
Registered User
 
Join Date: Aug 2004
Location:
Posts: 2,966
db/dc.b etc. are not 68000 instructions. They are assembler directives, which tell the assembler to include that data in the executable.

For whatever reason different assemblers have a different directive to do that. In ReSource you can switch between db/dw/dl and dc.b/dc.w/dc.l by clicking the Options 1 button, then changing Assembler from Macro68 to Assem.

For example, suppose you have a program which prints a text string. You need to include your string in the program somehow.
Code:
    lea  (String,PC),A0
    bsr  print_text
    ... more code here ...

String:
    dc.b "Hello world!",0
In ReSource you can set the code/data type of the current and following lines using lAmiga-C, lAmiga-B, lAmiga-W, lAmiga-L and lAmiga-A for code, bytes, words, longwords or ASCII string respectively.
mark_k is offline  
Old 20 April 2016, 21:47   #14
matthey
Banned
 
Join Date: Jan 2010
Location: Kansas
Posts: 1,284
Quote:
Originally Posted by Sim085 View Post
How come these instructions are different from one editor to another? and how come these instructions are not in the 68000 manuals?

(btw ... asm one accepted dc.b)
Disassembler output is often created for the favorite assembler(s) of the author. Most 68k disassemblers and assemblers use dc.<size>. The vasm assembler allows multiple formats depending on the compatibility mode.

dc.b, dc.w, dc.l
blk.b, blk.w, blk.l
db, dw, dl
byte, word, long

ADis, D68k and IRA disassemblers all use dc.<size> so the default ReSource output is less common.
matthey is offline  
Old 20 April 2016, 22:28   #15
Wepl
Moderator
Wepl's Avatar
 
Join Date: Nov 2001
Location: Germany
Posts: 677
Quote:
Originally Posted by matthey View Post
ADis, D68k and IRA disassemblers all use dc.<size> so the default ReSource output is less common.
the reason is probably that db/dw/dl will create the shortest source file, AFAIK all modern assembler do understand it
Wepl is offline  
Old 24 April 2016, 19:46   #16
Sim085
Registered User
 
Join Date: Apr 2009
Location: Lija
Posts: 463
I hit some more problems

I am not sure if this is related to what mark_k was saying. In the .asm file generated from ReSource I have some code as follows:

Code:
    BRA.B    START+$097C    ; line 1
    ORI.B    #????$31,D0        ; line 2
    ORI.B    #????$6F,????    ; line 3
    ????    ; line 4
ReSource manual says "If a line of code makes a reference to somewhere within the program that doesn't have a label yet, it will be shown as some offset from the label 'START', which is imagined to be attached to the first byte of the program.".

So with regards to 'line 1' I converted 097C from HEX to DEC (2428). I looked for this line in the .asm file and I can see this is a normal code. So why isn't ReSource creating a label like it does in other places? I am asking this to see if I am working this one right. Can I replace this with a label?

As for the question marks. ReSource manual says "ReSource displays question marks when the data type is code and there is no legal instruction at that location". So what can I do for line 2, 3 and 4?


Quote:
Originally Posted by mark_k View Post
Getting a disassembly to the state where reassembling the .asm file produces a working executable can be quite a long process.
Sim085 is offline  
Old 24 April 2016, 22:16   #17
mark_k
Registered User
 
Join Date: Aug 2004
Location:
Posts: 2,966
Okay, first of all there's little point in bothering to output a .asm file until you have the disassembly in a much more complete state, since you won't be able to re-assemble it without the assembler giving loads of errors. (Unless you're just using the .asm file to load into a text editor and navigate it, I guess.)

The offset in the example you gave (START+$097C) is in bytes relative to the start of the program. It has nothing to do with line numbers in the .asm text file.

In ReSource, move to the BRA.B START+$097C instruction and press the right arrow key. That will move to offset $97C in the disassembly. Do there seem to be valid instructions there? If so then the BRA.B instruction may well actually be an instruction, as opposed to data being disassembled as code.

Press the left arrow key to return to the BRA.B instruction, then press F6 to automatically generate a label at offet $097C.

The "instructions" after the BRA.B in your example are not code, but some kind of data. Move to the first ORI.B and press lAmiga-A to convert to ASCII string. Does that make sense? If not try lAmiga-W to convert to words.

It may be that the BRA.B isn't actually code either. Do the instructions before the BRA.B look normal/valid, i.e. without ??? in?

Rather than manually generating labels for every START+ reference, you can use the Project->Disassemble menu item and have ReSource do it for you. Sometimes it doesn't work for the whole executable for some reason, so you may need to select that menu item more than once.

ReSource's automatic disassembly isn't perfect and it may create labels where it's not appropriate. In that case you can move to the line with the bogus label and press - to remove it.
mark_k is offline  
Old 26 April 2016, 02:31   #18
Sim085
Registered User
 
Join Date: Apr 2009
Location: Lija
Posts: 463
So I would say the following code is valid...

Code:
00056C    TST.B    (A1)+
00056E    BNE.B    START+$056C
My understanding of the above code is that at line 056C it checks if the byte at address location A1 is a zero and increments A1 by one. At line 056E, if previous line returned false (i.e. - not zero) then it loops.

I did use the Disassemble option but parts like this one were left without labels.

Quote:
Originally Posted by mark_k View Post
Do there seem to be valid instructions there? If so then the BRA.B instruction may well actually be an instruction, as opposed to data being disassembled as code.

Now this one is more tricky for me as not really know if the results are what is to be expected. Given ...

Code:
    ORI.B    #????$6F,D0
    ORI.B    #????$6F,????
    dw    4
...
When I use LAmiga+A I do not get recognizable text. When I use LAmiga+W and I get the following:

Code:
    dw    0
    dw    $2264
    dw    8
    dw    $2064
    dw    4    ; the line at the end
...
Would it have an effect on the assembler if dw is used instead of dl or db? As this is not code I am not really interested in it at the moment however do not know if it would still stop me from re-assemble.

Quote:
Originally Posted by mark_k View Post
The "instructions" after the BRA.B in your example are not code, but some kind of data. Move to the first ORI.B and press lAmiga-A to convert to ASCII string. Does that make sense? If not try lAmiga-W to convert to words.
Sim085 is offline  
Old 26 April 2016, 09:56   #19
matthey
Banned
 
Join Date: Jan 2010
Location: Kansas
Posts: 1,284
Quote:
Originally Posted by Sim085 View Post
So I would say the following code is valid...

Code:
00056C    TST.B    (A1)+
00056E    BNE.B    START+$056C
My understanding of the above code is that at line 056C it checks if the byte at address location A1 is a zero and increments A1 by one. At line 056E, if previous line returned false (i.e. - not zero) then it loops.
Yea. Looks like common code to find the end of a string. It's odd that no label was generated but I'm no Resource expert.

Quote:
Originally Posted by Sim085 View Post
When I use LAmiga+A I do not get recognizable text. When I use LAmiga+W and I get the following:

Code:
    dw    0
    dw    $2264
    dw    8
    dw    $2064
    dw    4    ; the line at the end
...
Would it have an effect on the assembler if dw is used instead of dl or db? As this is not code I am not really interested in it at the moment however do not know if it would still stop me from re-assemble.
Not all data is text (some are numbers). There is no zero byte at the end so this is probably not text but it is difficult to know without labels to this data and without seeing what is after this.

It doesn't matter if dl, dw or db is used. It affects how compact and readable the data is but not the assembler output.
matthey is offline  
Old 26 April 2016, 22:59   #20
mark_k
Registered User
 
Join Date: Aug 2004
Location:
Posts: 2,966
Quote:
Originally Posted by Sim085 View Post
My understanding of the above code is that at line 056C it checks if the byte at address location A1 is a zero and increments A1 by one. At line 056E, if previous line returned false (i.e. - not zero) then it loops.

I did use the Disassemble option but parts like this one were left without labels.
Move to the BNE.B instruction and press F6 to create a label at offset $56C.

Quote:
Originally Posted by Sim085 View Post
When I use LAmiga+A I do not get recognizable text. When I use LAmiga+W and I get the following:

Code:
    dw    0
    dw    $2264
    dw    8
    dw    $2064
    dw    4    ; the line at the end
...
Would it have an effect on the assembler if dw is used instead of dl or db? As this is not code I am not really interested in it at the moment however do not know if it would still stop me from re-assemble.
It's always best to (try to) understand what data is. Does any code reference that data? For example, if the dw $2264 is at offset $1234, press F7 and set the string to search for to START+$1234. Then press F9 to search for that string. If you find code which uses that data, you can usually figure out whether it should be disassembled as byte, words or longwords.

In the case of the specific data you gave, it may be that the initial dw 0 is padding to longword-align the following data.


By the way, I highly recommend you download the ReSource PDF user manual, and follow the tutorial in it.
mark_k 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
asm code file errors and external file locations Brick Nash support.WinUAE 0 06 April 2015 18:14
Problem to load config file and quicksavestate Kloks support.WinUAE 23 30 March 2013 19:35
Cancelling load config file requester resets emulation mark_k support.WinUAE 2 18 February 2012 10:34
Help! Trying to Load .DMS file..... Triumph support.WinUAE 4 17 February 2009 21:37

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 14:20.


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