Forums

Sega Master System / Mark III / Game Gear
SG-1000 / SC-3000 / SF-7000 / OMV
Home - Forums - Games - Scans - Maps - Cheats - Credits
Music - Videos - Development - Hacks - Translations - Homebrew

View topic - What's the difference...

Reply to topic
Author Message
Consolemu
  • Guest
Reply with quote
What's the difference...
Post Posted: Sun Apr 23, 2000 5:38 am
In Motorola Assembly, what is the difference between Immediate and Absolute memory? I know that Immediate gives the absolute value but are they vice versa? Synonyms?

Is this...

LDA #$20

Any different from this?

LDA $20


Just curious...

Chris :o)
 
Flavio
  • Guest
Reply with quote
Post Posted: Sun Apr 23, 2000 6:44 am
Quote
> Is this...

Quote
> LDA #$20


In this case, 'A' would be made equal to $20.


Quote
> Any different from this?

Quote
> LDA $20


Here, 'A' would be loaded with the byte located at offset $20.


Quote
> Just curious...

That's just one of the many nasty Motoroloid traps for Intel immigrants. Watch your step. ;)


Cheers,
F.
 
  • Site Admin
  • Joined: 25 Oct 1999
  • Posts: 2029
  • Location: Monterey, California
Reply with quote
Post Posted: Sun Apr 23, 2000 6:46 am
Quote
> In Motorola Assembly, what is the difference between Immediate and Absolute memory? I know that Immediate gives the absolute value but are they vice versa? Synonyms?

> Is this...
> LDA #$20
> Any different from this?
> LDA $20

this is 6502, right?
My 6502 syntax is rusty, but I'd say both the above instructions are identical (if using the pound sign is even legal, may depend on the instruction). Both instructions are immediate loads, that is, they load the accumulator with the number $20.

The absolute version would like like this

LDA ($0200) ;Load accumulatir with the byte at memory location $0200

Summary:
Immediate Data: The instruction specifies the actual numeric data directly.
Absolute: The instruction specifies the exact memory location to fetch data from.
Indirect: The memory location to fetch data from is not specified directly (in this case, the memory location may be found in registers, or memory (page zero in 6502), and may be offset by other registers or numbers, depending on the processors).

Examples:
[IMMEDIATE]
lda $40 ;Loads the accumulator with the number $40 (6502)
ld c,$40 ;Loads register C with the number $40 (z80)
add a,$40 ;Adds $40 to the accumulator (z80)
move.w #$40,d0 ;Loads register d0 with $40 (68000)
add.w #$40,d0 ;Adds $40 to register d0 (68000)

[ABSOLUTE]
lda ($0200) ;Loads the accumulator with whatever value is stored inmemory location $0200 (6502)
sta ($0200) ;Stores the value of the accumulator into memory location $0200 (6502)
ld a,($c000) ;Loads the accumulator with whatever value is store in memory location $c000. (z80)
ld ($c000),a ;Stores the value of the accumulator in memory location $c000. (z80)
move.w $dff180,d0 ;Loads register d0 with the word stored in memory location $dff180
move.w d0,$dff180 ;Loads the (word) value of d0 into memory location $dff180

[INDIRECT]
lda ($10) ;[tricky] Get the address that memory location $10 and $11 point to, and load the accumulator with the byte stored at that location.(6502)
;;;For example, if $10 and $11 contain the values $03 and $20, fetch the byte at $2003 and put it in the accumulator.
ld e,(hl) ;Load register e with the byte at the memory location pointed to by hl (z80)
;;For example, if h is $c0 and l is $f0, load e with the value at memory location $c0f0
ld (de),a ;Store the value of the accumulator into the memory location pointed to by de (z80)
;;If d is $c0 and e is $f0, store the accumulator into memory location $c0f0.
ld d0,(a0) ;Loads d0 into the address pointed to a0. (68000)
;;If a0 points to $cff000, load d0 into that address.
ld (a0),d0 ;do I have to say it?

Instructions can use a combination of these modes (move.w #$10,$dff180).
And then there indirect addressing with displacement. Some 6502 examples:
sta ($20),x ;Find the address that is contained in memory locations $20 and $21, add x to that address, and store the accumulator into it.
lda ($20,y) ;Find the address that is contained in memory locations ($20 + y) and ($21 + y), and load the value at that address into the accumulator.

16-bit and later processors often have a ton of variations on that theme. The z80 doesn't use much indirect addressing with displacement (only the instructions which use ix and iy, and only with immediate displacements).


That help?
  View user's profile Send private message Visit poster's website
  • Site Admin
  • Joined: 25 Oct 1999
  • Posts: 2029
  • Location: Monterey, California
Reply with quote
corrections
Post Posted: Sun Apr 23, 2000 6:53 am

Quote
> this is 6502, right?
> My 6502 syntax is rusty, but I'd say both the above instructions are identical (if using the pound sign is even legal, may depend on the instruction). Both instructions are immediate loads, that is, they load the accumulator with the number $20.

no, they weren't. I got 6502 syntax confused with z80. sigh. In motorola syntax (6502 and 68000) the # signifies that the operand be treated as a literal value, and without the #, it signifies that the operand be treated as an address to fetch data from.
Told you I was rusty.
In zilog syntax, the # isn't used, all unqualified operands are treated as literal, and numbers surrounded with ()'s signify that the operand be treated as an address.
I couldn't even say what the intel equivelant is, I've never used it (only AT&T).

Quote
> The absolute version would like like this

> LDA ($0200) ;Load accumulatir with the byte at memory location $0200

I guess that should be just $0200
Quote
> lda $40 ;Loads the accumulator with the number $40 (6502)
lda #$40

Quote
> lda ($0200) ;Loads the accumulator with whatever value is stored inmemory location $0200 (6502)
lda $0200

Quote
> sta ($0200) ;Stores the value of the accumulator into memory location $0200 (6502)
sta $0200
Quote
> lda ($10) ;[tricky] Get the address that memory location $10 and $11 point to, and load the accumulator with the byte stored at that location.(6502)
I think that's right though.

Quote
> Instructions can use a combination of these modes (move.w #$10,$dff180).
> And then there indirect addressing with displacement. Some 6502 examples:
> sta ($20),x ;Find the address that is contained in memory locations $20 and $21, add x to that address, and store the accumulator into it.
> lda ($20,y) ;Find the address that is contained in memory locations ($20 + y) and ($21 + y), and load the value at that address into the accumulator.
  View user's profile Send private message Visit poster's website
Flavio
  • Guest
Reply with quote
Re: corrections
Post Posted: Sun Apr 23, 2000 7:06 am
Quote
> I couldn't even say what the intel equivelant is, I've never used it (only AT&T).

Intel-style assemblers use square brackets to denote indirection, like in MOV AL, [$20], as if we needed yet another assembler syntax.
Quote from Linux User's Guide: "The good thing about standards is that there are so many to choose from." :/


Cheers,
F.
 
Consolemu
  • Guest
Reply with quote
I found it
Post Posted: Mon Apr 24, 2000 3:12 am
Sorry to post that message but I desperatly searched high and low and I usually go here as my utopia or last hope...The only problem is I totally forgot about my old PC. My old PC has TONS of info that I gathered a long time ago on stuff that's kinda hard to find today (weird, eh?). Anyway, in one of the documents (A damn good one!!) I found a long time ago, explained the Motorola operand stuff...

Immediate: A value that's directly used with register memory. Ex.

6502: LDA #$FF
68000: LOAD.B #$FF, D0


If you didn't include the # sign, you would be using...

Absolute: A value used to refer to a memory address, whether it be Zero Page or greater than Zero Page...

6502: LDA $FF
68000: LOAD.B $FF, D0


In the previous lines, the memory in address FF would be loaded into the register. Zero Page works and is just like Absolute, but it deals strictly with 8-bit values.

There's one more method called Indirect...
Indirect: A value used to refer to a memory address by taking the values in the memory address and the following address. This method is only used in Jumping instructions. As confusing as it sounds, it works like this...

6502: JMP ($FF)
68000: JUMP ($FF)

The address that the processor will jump to is contained in addresses $FF and $100. A better example. Picture memory...

offset/value
$00FE: #$27
$00FF: #$00
$0100: #$01
$0101: #$07
...

The processor will take $00 (what's in $FF) and $01 (what's in $100), merge them together to make a Word address, and then jump to it (jumps to $0100). Now, the order that the chip merges the following bytes is chip specific. The previous code was for a 6502 but I think it's backwards for a 68000. Like, either #1000 or #0010...I'm not sure.

As bizzare as this stuff looked as I was reading it, it now makes 100% sense. It makes even more sense on the 68000 because of it's type of syntax. You know exactly what's going on with the operands, there's no interpretation involved. No offense Zilog or Intel but this is something that you don't have. For the Z80 and 80x86 users out there, you do the same thing the other chips do except in different syntax...

Immediate = A solid value (8-bit or larger) is sent to the register.

8086: MOV AX, $F012
Z80: LD BC, $F012


Absolute = The value in an 8-bit or larger address is sent to the register.

8086: MOV AL, [$FF]
Z80: LD B, [$FF]


One thing that I haven't found with the Motorolas yet are pointers. That's kind of a necessity when you're dealing with complicated programming. Ex.

8086: MOV BL, [AL]
Z80: LD B, [A]

Damn, I'm beginning to compare chips and this is a totally different conversion; one that could go on for hours. But anyway, that's what I discovered and that's how they work (double check me if you see something wrong).

Chris :o)
 
  • Site Admin
  • Joined: 25 Oct 1999
  • Posts: 2029
  • Location: Monterey, California
Reply with quote
Re: I found it
Post Posted: Mon Apr 24, 2000 5:49 am

Quote
> Absolute = The value in an 8-bit or larger address is sent to the register.
>
> 8086: MOV AL, [$FF]
> Z80: LD B, [$FF]
er, well, in z80 you use parenthesis to denote that an operand should be treated as an address, as in "ld a,($c220)" (source is absolute, destination is register) or "ld (hl),b" (source is register, destintion is indirect).
Note that the different modes (absolute, immediate, indirect, register, hybrids thereof) apply to each of the operands in an instruction. In the 8-bit processors, one of the operands is nearly always a register (even if one of the operands is implied in the mnemonic, as with the 6502... not to rekindle the semantic battle with Nyef). In later processors, you may be able to mix them.
Of course, you'd never have an immediate destination. ("Load the number 3 with the number 4"?)

Also, you can't load the contents an arbitrary memory location directly into register b like that, much as I keep trying to do that sort of thing. You'd have to load it into a and transfer that to b, or have (hl) point to the memory location.



Quote
> One thing that I haven't found with the Motorolas yet are pointers. That's kind of a necessity when you're dealing with complicated programming. Ex.
>
> 8086: MOV BL, [AL]
> Z80: LD B, [A]
the above instruction is not a valid Z80 instruction, and doesn't make much sense (z80's don't use 8-bit pointers like the 6502)

Z80: LD B, (HL) ;Treat HL as a pointer
Pointers are the application of indirect addressing.

68000: move.w d0,(a0) ;A0 is treated as a pointer.
6502: lda ($20) ;Memory locations ($20) and ($21) are treated (combined) as a pointer.




Quote
> (double check me if you see something wrong).

Can do!
  View user's profile Send private message Visit poster's website
Johannes Holmberg
  • Guest
Reply with quote
Small correction
Post Posted: Mon Apr 24, 2000 4:18 pm

Quote
> 6502: lda ($20) ;Memory locations ($20) and ($21) are treated (combined) as a pointer.

I think the 6502 requires an index here, like:
lda ($20,x)
or
lda ($20),y

/Johannes
 
Consolemu
  • Guest
Reply with quote
Yup, you're right
Post Posted: Tue Apr 25, 2000 5:27 am
Quote
> I think the 6502 requires an index here, like:
> lda ($20,x)
> or
> lda ($20),y

You're absolutely right. My bad. I pretty much know the many types of combinations and instructions for the 6502 and what I wrote was wrong now because I wrote all 148 different combinations and instructions (No I'm not crazy). You can't Indirectly get data like that, not unless you use X or Y with it. You can only use Indirect byself with jumping. Glad you pointed that out so I don't look totally stupid.

Quote
> /Johannes

Chris :o)
 
Johannes Holmberg
  • Guest
Reply with quote
?
Post Posted: Tue Apr 25, 2000 7:03 am
Quote
> > I think the 6502 requires an index here, like:
> > lda ($20,x)
> > or
> > lda ($20),y

> You're absolutely right. My bad.

I thought Heliophobe wrote the bad code?
Oh well... :)
 
Consolemu
  • Guest
Reply with quote
Damn...
Post Posted: Tue Apr 25, 2000 10:16 am
Quote
> I thought Heliophobe wrote the bad code?
> Oh well... :)

Humm...I feel even more dumb. I lost track of the name to the postings. Well, at least I fully understand it now.

Chris :o)
 
Reply to topic



Back to the top of this page

Back to SMS Power!