flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
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 |
|||
![]() |
|
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 |
|||
![]() |
|
rhyno_dagreat
Thanks Loco, Goplat! Makes sense! It seems like I could use that in my own 512 byte 32 bit mode OS!
![]() |
|||
![]() |
|
LocoDelAssembly
Goplat, yes, I forgot to talk about the GENERAL use
![]() (I thought he was wondering about its "over use" on 512 byte OSes only) |
|||
![]() |
|
Plue
bp is usually used for array access in compiler generated code. And also it can be used as a general-purpose register.
|
|||
![]() |
|
rhyno_dagreat
Thank you all for the help!
|
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.
Website powered by rwasa.