RE: A89: hello world


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

RE: A89: hello world




Woohoo some real code!!!
okie... let the pro explain...

> Hi, can someone please help me understand this supposedly simple code?
> Let me start by stating what I know or what I think I know:
> ***any help would be greatly appreciated***
> -thanks-
> Steven
>
> line 1: This does a jump to the utility library in order to clear
> the screen
> line 2: This pushes 2 onto the stack
> line 3: 2 was pushed onto the stack because of the ti rom call
> FontSetSys:the
> 2 sets the font to normal size (?).  Is a7 used on all rom calls?
> line 4: Because you pushed 2 onto the stack you must also pop the
> 2 off the
> stack: Why does this have to be done?  and why can't you just
> add.w or add.b?

The stack is 32-bit. Thus, you need to move the stack value back 2
bytes. The stack value is 32-bit, thus use addq.l or add.l

> line 5: This pushes 4 onto the stack
> line 6: This loads the address of string to the a0 register: what is the
> "(pc)" for?

It's the way to show the "absolute" address of the string, so the rom
call can find directly locate the string.

> line 7: This pushes the address of the string to the stack: what
> happened to
> the 4 that was pushed to the stack?

The four is still there...but now it's four bytes below... need me to
explain stacks?

okie... a little rundown on stacks...
a7 is just a 32-bit number. there's nothing really important about the
number. It could
be $4440 or it could be $3300. However, the value (a7) is most important.
Say, for example,
a7 = $4440, (a7) is the value at $4440. So, when you do -(a7), A7 equals to
either
 $443E or $443C.

Okie... so how does this mix in? Well, say...
  at line 5,   a7 is equal to $4440.
   after line 5, a7 will equal to $443E, and ($443E)= $4, the color
  at line 7,   a7 is equal to $443E.
   after line 7, a7 will equal to $443A, and ($443A)= address of the string.
  at line 8,   a7 is equal to $443A,
   after line 8, a7 is equal to $4438, and ($4438) = 0, the horizontal
position
  at line 9,   a7 is equal to $4438
   after line 9, a7 is equal to $4436, and ($4436) = 0, the vertical
position
  okie, when calling that rom call, a7 is still equal to $4436.
  got that? this is what it looks in RAM

| $4436 | $4438 | $443A | $443C | $443E | $4440 |
   0000    0000   string address   0004
  vert.   horiz.  string address  color

> line 8: This pushes 0 onto the stack: what happened to the 4 and
> the address
> of the string that was previously pushed onto the stack?
> line 9: This pushes 0 onto the stack again: why is it pushed again?
> line 10: This does the rom call DrawStrXY which displays the
> string: maybe i



> think i know what is going on: the first thing that you need to do to call
> this rom call is to push the address onto the stack then you must
> push the 2
> coordinates onto the stack:0,0 and the rom call takes care of the
> rest?  But I
> still don't know where the 4 comes in place.
> line 11: It says restore the stack pointer...but where does the
> 10 come from:
> i only count 4 then 0 then 0 again=4...i don't know how that
> works.  Why do
> you even have to "restore" the stack...i remember with the z80
> you didn't HAVE
> to pop a register back after pushing it?

Okie, so what is a7 after step 10? well, it is $4436, but before we did
all this crap, it was $4440. So you subtract... $4440 - $4436 is equal to
$0A or #10.

> line 12: this does a jump to the utility library which basically
> does a loop
> waiting for a key to be pressed.
> line 13: returns to the shell when a key is pressed...What other return
> statements are there?

that's it... pretty simple stuff... reply if u don't understand or if other
ppl don't understand.  I like it when we're discussing code, not concepts...

>
> _main:
>     ; Execution will start here, at the _main label
>   1  jsr      util::clr_scr          ; clear the screen
>   2 move.w   #2,-(a7)               ; use font #2 (large font)
>   3  jsr      tios::FontSetSys       ; set the font
>   4  add.l    #2,a7                  ; clean up the stack
>   5  move.w   #4,-(a7)               ; move the first param to the stack
>   6  lea      string(pc),a0          ; move adress of string to the stack
>   7  move.l   a0,-(a7)
>   8  move.w   #0,-(a7)               ; push position
>   9  move.w   #0,-(a7)               ; push position
>  10 jsr      tios::DrawStrXY        ; call the DrawStrXY ROM function
>  11 add.l    #10,a7                 ; restore the stack pointer
>  12 jsr      util::idle_loop        ; library routine which waits
> until a key
>                                     ; is pressed.
>  13 rts
>
> string:
>     dc.b "Hello, World!",0
> _comment:
>     dc.b "Hello World example",0
>
>     end
>


References: