Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Assembly Language Programming (ALP) Forum (http://www.go4expert.com/forums/assembly-language-programming-forum/)
-   -   Basic assembly language questions (http://www.go4expert.com/forums/basic-assembly-language-questions-t15293/)

Shafqat 28Nov2008 17:55

Basic assembly language questions
 
Hi,

I just exposed myself to assembly language a few days ago so these questions might seem dumb but please bear with me :)


1) What does dc.b mean? It is used in the code in this context:

dc.b "Enter your name." , CR, LF

Does dc.b mean define constant.byte? If so how is this sentence a byte?


2) What does org mean?


Any help would be highly appreciated.

Thanks

xpi0t0s 28Nov2008 19:27

Re: Basic assembly language questions
 
You don't say what processor and assembler you're using so it could mean anything. Different processors use different languages, and different assemblers for each processor implement the language slightly differently, so for the answer to mean anything it has to be in the context of a specific processor (or processor family) and assembler.

So it's entirely possible that dc.b means define constant byte, or possibly bytes, and that the particular assembler you're using allows you to define a series of bytes rather than making you do dc.b 'E' dc.b 'n' dc.b 't' etc, which would be really tedious.

org again depends on the processor and assembler, but often it's short for "origin" and defines what address the program should be compiled to.

Shafqat 28Nov2008 19:54

Re: Basic assembly language questions
 
Thanks, I'm using Coldfire 5307 processor

One more question:

What is the difference between data and address register?

The way I understand it is data register stores data like integers etc. and address register stores addresses.

But then what does the foll. code mean:

move.1 D1, -(A7)

move #9, D1

jsr print_out

move.l (A7)+, D1

Print_out is a subroutine in the code among several other subroutines and I notice that the code in intalics marks the near end and beginning of every subroutine. What does it mean?

Thanks

xpi0t0s 29Nov2008 00:17

Re: Basic assembly language questions
 
Data and address registers are essentially the same thing; both store numbers, but some instructions will only work on data registers and some only on address registers. In general you should use data registers to store data and address registers to store addresses, but you can crossover if necessary. If you're doing pointer arithmetic you could use both types.

move.l d1, -(A7) moves the contents of D1 to the memory location pointed to by A7-4 (or possibly A7-1; I'd have to RTFM to be sure, but A7-4 makes more sense than A7-1)
move #9,D1 sets D1 to 9
jsr calls a function - I don't know what that does
move.l (A7)+,d1 moves the contents of memory location pointed to by A7 to D1, and increases A7 by 4 (or 1).

So A7 is probably being used as a stack for safe storage of whatever is in D1, and the references to -(A7) and (A7)+ are equivalent to push and pop instructions in other processors. It's a long time since I looked at 68000 programming (Amiga days...sigh...) but I have a vague idea that A7 is generally used as the processor stack pointer. If that's the case then jsr probably modifies A7 too; it'll push the return address onto the stack.

Shafqat 5Dec2008 12:41

Re: Basic assembly language questions
 
Another question:

What is the difference between A1 and (A1) ?

xpi0t0s 5Dec2008 13:04

Re: Basic assembly language questions
 
A1 is the register, (A1) is the memory location pointed to by A1. So if A1 contains 1000 and D1 contains 50, move D1,A1 sets A1 to 50, but move d1,(a1) sets memory location 1000 to 50 and doesn't change A1 itself.

Shafqat 11Dec2008 14:28

Re: Basic assembly language questions
 
Sorry I'm being slow but is this what you mean:

move D1, A1 implies A1 is now not pointing to memory location 1000 but instead is pointing to memory location containing 50

move D1, (A1) implies memory location 1000 is set to contain 50.

is 1000 the address or the contents?

Thanks

xpi0t0s 11Dec2008 16:35

Re: Basic assembly language questions
 
> move D1, A1 implies A1 is now not pointing to memory location 1000
correct.

> but instead is pointing to memory location containing 50
No, A1 is now pointing to memory location 50

> move D1, (A1) implies memory location 1000 is set to contain 50. is 1000 the address or the contents?

Memory location/address 1000 contains the value/has contents 50. There is a 50 stored at address 1000.

move 50,d1
move 1000,a1
move d1,(a1) // stores 50 at 1000

move 1000,d1
move 50,a1
move d1,(a1) // stores 1000 at 50

move 1000,d1
move d1,a1
move d1,(a1) // stores 1000 at 1000

Probably the best bet is to download an emulator and watch how memory is affected by simple code examples like the above. If you restrict all values to, say, less than 25, and the emulator has RAM at addresses 0-25, then you should be able to keep track of everything without taking up too much screen space or getting confused scrolling from one area to another trying to find the value.

Shafqat 11Dec2008 16:39

Re: Basic assembly language questions
 
Sounds like a good idea, will do that. Thanks.

xpi0t0s 11Dec2008 16:54

Re: Basic assembly language questions
 
Since Coldfire 5307 is based on the 68000 chip this may be of interest: http://www.easy68k.com/
It's something I keep meaning to try out but time shortages have prevented it so far.


All times are GMT +5.5. The time now is 21:02.