LF: For Newbies... IV


[Prev][Next][Index][Thread]

LF: For Newbies... IV



First: i am sorry: i made a mistake...
i shouldn' t have used the lea statement like this: "lea
         string(pc),-(A7)"
it is impossible: lea is an inst which calculates the adress and stores it in
an adress reg... 
theis was rigght : lea    string(pc),A0
                          move  A0,-(A7)

so.... sorry ! 

second: there is sth which should have been in the first part... adresses... 
an adress is a number which indicates the place of some info in mem... the
unit of an adress is the byte ( 8 bits )... this explains the 10 in "lea
 10(A7),A7"

third: a counsel... try not to use such inst as lea  10(A7),A7 ... add
 #10,A7 is much simpler and you won' t make a mistake...

IV ) conditionnal branch

1 ) labels
   
in an ASM prog , you may define labels: if you have done some programming on
a casio calc or on some old basic, there was the goto function... 
"goto  <label>" meant that when executing the goto statement, the computer
had to go at the label pointed by goto. ( it could be combined with a if
statement ) 
we got the same in ASM.

to define a lable, you write: 
name_of_label:
that' s all ! the ":" is important: it is him which helps the compiler to
recognize the label...

2) comparisons, status register... 

to compare 2 operands, you execute a cmp statement... 

cmp  D0,D1

this does: D1 - D0 and affects the bits of the status register depending on
the result of this substraction. important: the result is not stored in
memory or anywhere: it is virtual... 
now: the status reg: i have no time to go through it: look at jimmy' s guide
to know how the flags ( the bits ) of this reg are affected...
You have to know that the result of a standard arithmetic operation usualy
affects the status reg in the same way: you may thus remove some cmp from
your programs... 

3 ) conditionnal branch...

the statement is: Bxx  where xx is one the 14 ( or more: no courage to check
) extensions ( check jimmy' s guide: it is explained in the inst section ) 

ex: Bcc, Bhi... 

here is a way to work with them: 

let' s imagine that you write: 
cmp    B , A

then bxx will branch to the label if: 

when working with unsigned integers: 

A>   B            Bhi
A>= B            Bcc
A<=B             Bls
A<B               Bcs
A=B               beq
A<>B             bne

with signed integers

A>B              bgt
A>=B            bge
A<=B            ble
A<B               blt
A=B              beq
A<>B            bne

and, to test the V and N flags: 
bvc if V is not set and bvs if not set 
bpl  if N is not set and bmi if not set 

4 ) other inst

i am afraid but i don' t know how to use the dbxx inst... 
this one seems to be powerfull.. you should have a look at it


V )  Structured programming in ASM

More than any other langage, ASM is extremly complex: listings get longer and
longer, most of the time unreaddable, no one but you can understand the
program... It becomes very quickly impossible ... 
There are some solutions... 


1 )  pseudo code

before writing anything in ASM, you MUST know what you will do.. 
I remember my programming some things in pascal or basic some time ago... I
began to write things on the screen without even knowing how i would do what
i had in mind. If this was possible  for very simple progs, it is no more
possible for an ASM prog ( because of its complexity and lenght ) 
So: you need fist to write a pseudo code: it is a text ( preferably in your
own language at the begening ) which describes the general structure of the
program... 
for exemple, if you are writing a doom like engine.. ( my case ) 
for ray from 0 to 150 

launch ray. 

calculate dist to the first object. 

render the slight portion of picture based on the distance to the first
object encountered.

end_for

easy, not ? 
this is the first version: slowly by slowly, you try to go deeper, you
explain with more detail what will be done in the "launch ray " section... 
While writing the pseudo code, you build a " table descriptor": there, you
keep track of each variable, its use, its type, the different values it will
take, its range, its initialisation... 

then at last, you got a doc which can be understood by anyone... ( taking
time of course )  

2 )  The program 

on this basic structure, you can write your program.... 
it is very imp that you keep in mind that structures as "if then else endif"
 are very easy to code...
for exemple: 
if_1:
   cmp D0,D1
   bcc   else_1
then_1:
; your code
    bra end_if_1
else_1:

end_if_1:

There is a way to traduce all structures in such a way: i will release a
complete setup later... then, at last, you may add comments at the right of
your code to make the comparison between the pseudo code and your program
easier... 


sorry: i have to leave, will go on later... 

Mathieu, <hm lacage@aol.com>

PS: for those who think this is nonsense ,  structured programming... Well: i
discovered this a month ago in book on ASM on 68 k processors... It DOES help
! i can tell ! 


Follow-Ups: