flat assembler
Message board for the users of flat assembler.

Index > Main > Register Question

Author
Thread Post new topic Reply to topic
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
Okay... I'm sure we've all used the general purpose registers, index registers, and segment registers at one point in our programming history. I'm sure a few of us have also used the Stack Pointer (sp) register at one time or another. I feel stupid saying this now, but I just learned there was a Base Pointer (bp) register!

From what I've used with the SP register, it's used to set up the starting point of where the stack will be in memory. I've looked at the 512 Byte OS, and I'm wondering what is the BP register exactly used for? Is it general purpose or something? :-/ Embarassed Laughing

Anyways, thanks y'all!

P.S. - Sorry I've been gone for a while, been busy with college! It's great to be back into this though!
Post 02 Dec 2006, 02:01
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
The reason for using BP a lot for those 512-byte chalenges is this http://board.flatassembler.net/topic.php?t=6078
Code:
  ;------------------------------------------------------------------
  ; BP-relative addressing
  ; this trick allows us to use addressing with BP + byte sized displacement,
  ; instead of word sized immediate offset, for example "inc [some_label]"
  ; becomes "inc [bp + some_label - BPVAL]". Only usable for offsets from
  ; BPVAL-128 to BPVAL+127
    
Post 02 Dec 2006, 03:19
View user's profile Send private message Reply with quote
Goplat



Joined: 15 Sep 2006
Posts: 181
Goplat
LocoDelAssembly: 512 byte demos are not exactly typical code though...

Anyway, BP/EBP is usually used as a frame pointer (pointer to the base of the stack frame). In 16-bit code, you could not address relative to SP, so if you wanted to access the stack in places other than the current stack pointer, you had to use BP. BP was the most suitable register for this purpose, since unlike the other three addressable registers (BX, SI, DI) a memory operand using BP would default to the SS segment rather than DS.

Here is a (16-bit) example of using BP to access function parameters on the stack.
Code:
        push 100
        push 200
        call add
        ; now AX = 300

add:    push bp
        mov bp,sp
        mov ax,[bp+4]   ; [bp+4] = 200
        add ax,[bp+6]   ; [bp+6] = 100
        pop bp
        ret 4
    
Post 02 Dec 2006, 03:29
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
Thanks Loco, Goplat! Makes sense! It seems like I could use that in my own 512 byte 32 bit mode OS! Wink
Post 02 Dec 2006, 03:29
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Goplat, yes, I forgot to talk about the GENERAL use Laughing
(I thought he was wondering about its "over use" on 512 byte OSes only)
Post 02 Dec 2006, 04:12
View user's profile Send private message Reply with quote
Plue



Joined: 15 Dec 2005
Posts: 151
Plue
bp is usually used for array access in compiler generated code. And also it can be used as a general-purpose register.
Post 02 Dec 2006, 09:49
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
Thank you all for the help!
Post 04 Dec 2006, 03:43
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.