flat assembler
Message board for the users of flat assembler.
Index
> Main > Implement Stack in FASM? |
Author |
|
crc 16 Aug 2004, 15:49
Hmm, a LIFO (last in, first out) stack. Well, I have a plenty of experience with these . This sample doesn't include input or output of the numbers, but it does work.
Code: ; These macros are from RetroForth macro dup { sub esi,4 mov [esi],eax } macro drop { lodsd } macro swap { xchg eax, [esi] } macro upsh a { dup mov eax, a } macro upop a { mov a, eax drop } ; LIFO Stack example ; Adapted from the RetroForth 4.x/5/x/6.x/7.x source code ; This implements enough of the stack to enable basic Forth primitives ; (implemented by macros) to be used. Provided primitives are dup, drop, ; and swap. ; format ELF executable entry start start: mov esi, mystack (ESI points to stack memory) upsh 1 ; Put the numbers 1 - 5 on the stack upsh 2 ; upsh 3 ; upsh 4 ; upsh 5 ; At this point, 1 is on the bottom and 5 is on the top upop ebx ; get the top value from stack and place in ebx ; subsequent calls to 'upop' will fetch the other values ; from the stack xor eax, eax ; Exit the application (this is for Linux) inc eax ; int 0x80 ; stack_space rb 100*4 ; Reserve space for 100 numbers mystack rb 4 ; Start of the stack stacK_buffer rb 10*4 ; 10 space buffer for overflows Some notes on the macros:
EAX holds the top item on the stack, ESI is a pointer to the stack memory. All values on the stack are 32-bit integers. |
|||
16 Aug 2004, 15:49 |
|
Dragontamer 16 Aug 2004, 17:39
If you only need temp stack space...
You could just use push/pop But crc's is more versitile |
|||
16 Aug 2004, 17:39 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.