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