28 November 2010, 23:17 | #1 |
Registered User
Join Date: Nov 2010
Location: .
Posts: 385
|
REQ:ASM How to use buffers
Hello everyone,
pre-Commodore bankrupt Amiga user writing here (IRL developer on modern stuff), having fun with MC68000 assembly in his free time. I'm dutifully following the good Amiga Machine Language ebook, two lines per day because I like to fully understand everything - so I test a lot of personal variations of what I read. This is to say that I don't mind spending hours staring at the Devpac debugger moving stuff to/from registers. So, back in topic, I'm trying to understand how to use a buffer and how can I move the "visible window" on A(n) from the debugger. Everytime I issue a "(a0)+" instruction the pointer to the register shifts forward and I don't see anymore the value inserted unless I "go back" with a SUBQ. I usually use ADDQ and SUBQ to visually move the register cursor and check the values - this looks kind of lame, I guess. However there's something puzzling me, please have a look at the following code snippet: 1: run: 2: lea buffer,a0 ; removing this instruction or ... 3: move.w #2,(a0) ; changing this to (a0)+ or ... 4: subq.l #1,a0 5: move.w #3,(a0) ; removing this instruction: solves. 6: rts 7: 8: buffer: 9: dcb.w 9,0 10: 11: end Questions: 1) What is the real purpose of defining a 'buffer' in this code? I can access to A0 register either way. 2) If I run this code into the debugger, at line 6 in the disassembly window the RTS changes into a DC.W $4E00 and eventually falls into an illegal exception. As commented on line 2,3 and 5 slightly changing the code makes the RTS to stay there and be executed. Can you give me an insight on how to explain this behaviour? Thanks a lot. Antonio |
29 November 2010, 00:46 | #2 |
2 contact me: email only!
Join Date: May 2001
Location: Auckland / New Zealand
Posts: 3,187
|
a0 is just an address register, no actual block of memory is allocated. They just contain pointers to addresses (effectively numbers). The block of memory called buffer means that chuck of memory is set aside and can be referenced at any point in your code (which might be huge) by referencing the name buffer.
The rts instruction is $4e75 in hexadecimal. When you do your subq.l, you are moving the address register a0 back one byte so it's pointing to the $75 chuck of memory. Then you move the word #3 into it (illegal on 68000, but I guess devpac allows it as a 68020+ instruction or something) meaning you would now have $4e $00 $03 as 3 consecutive memory locations. Now a0 points to $4e00! |
29 November 2010, 08:48 | #3 | |
gone
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
|
Hello jman
The problem with the code is this: Quote:
I know what you mean about checking values in a debugger though. When you use: Code:
move.w #value,(a0)+ But, if you want to see what got placed in a0 before the post increment was done and you have a spare data register available (in this case, I'll use d7 as the example spare register) then you could do this line of code after your move.w to (a0)+: Code:
move.w -2(a0),d7 Hope that helps. |
|
29 November 2010, 09:35 | #4 | |||
move.l #$c0ff33,throat
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,865
|
Quote:
Quote:
Quote:
F.e. you could have code like this: lea buf,a0 move.w #1,(a0)+ ; a0 points to buf+2 after that instruction move.w #2,(a0)+ ; a0 points to buf+4 after that instruction If you only need to store one value, this would be totally fine and all you need: buf dc.w 0 ; allocate 1 word Hope that helps, if not feel free to ask. Last edited by StingRay; 29 November 2010 at 09:41. Reason: additions |
|||
29 November 2010, 10:26 | #5 | |
gone
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
|
Quote:
I'll blame it on this very cold early morning. |
|
30 November 2010, 23:13 | #6 | ||
Registered User
Join Date: Nov 2010
Location: .
Posts: 385
|
@everyone: thanks for your kind and prompt contribution.
I took some time to experiment and think over your suggestions. Some things you mentioned are clear, others confused me more (I'm a total beginner, that was clear in the first place), so here are some further questions that arised: Quote:
EDIT: I've found this: http://www.sarnau.info/atarirotection_speedball. Looks interesting. Still I don't understand what are those hex values next to each ASM instructions. Quote:
Code:
run: lea buf,a0 move.w #8,(a0)+ move.w #6,(a0)+ move.w #4,(a0)+ move.w #2,(a0)+ lea buf,a1 rts buf: dc.w 1,2 Again, thanks for your kind help. Antonio Last edited by jman; 30 November 2010 at 23:44. Reason: added link |
||
01 December 2010, 00:54 | #7 | ||
2 contact me: email only!
Join Date: May 2001
Location: Auckland / New Zealand
Posts: 3,187
|
Quote:
Any cracker worth their salt knows common ones off the top of their head like: $4e71 = nop $4e75 = rts $7000 = moveq #0,d0 $7200 = moveq #0,d1 $60xx = bra * + (xx + 2) = eg. $6002 will skip ahead 4 bytes from the instruction. Quote:
However, code like this: Code:
lea $400,a0 _1 move.l #0,(a0)+ bra _1 |
||
01 December 2010, 01:41 | #8 | |
Registered User
Join Date: Nov 2010
Location: .
Posts: 385
|
Quote:
Definitively interesting. With such insights, concepts like memory protection, opcodes and so on now are much more clear. Thanks, really. g'night. |
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[REQ:ASM] Reading a keystroke | jman | Coders. Tutorials | 34 | 17 August 2023 12:36 |
[REQ:ASM] Sprite collisions basics | jman | Coders. Tutorials | 5 | 03 September 2011 00:07 |
[REQ:ASM] Loading a static image and its palette | jman | Coders. Tutorials | 3 | 04 June 2011 14:08 |
[REQ:ASM] Assembling and running | jman | Coders. Tutorials | 9 | 07 May 2011 18:39 |
REQ:ASM getting elapsed time on A1200 | jman | Coders. Tutorials | 18 | 11 January 2011 22:24 |
|
|