Will someone please explain the use of the stack for me?
Posted: Wed Apr 18, 2012 3:36 pm
I am trying to make use of the stack in a calculator function I am writing for my OS. I want it to store the first number someone types in to the stack, and pop it into the si register to be added with the number with the number in the di register (which was typed in after the push), and then print the si register to the screen. I have created a .bss section with some bytes reserved for the stack in it, but I can not fathom how to use the push and pop instructions with my newly created stack space. Here are some short snippets of my code:
I also need to tell you that this is kernel code, I am using syslinux as my bootloader, so I do not need to worry about passing 512 bytes. Any help would be appreciated.
Code: Select all
SECTION .text
start:
mov ax, 0x07C0
mov ds, ax
mov es, ax
mov sp, stack_end
Code: Select all
.calc:
.calcloop:
mov si, math_prompt
call print_string
mov di, buffer
call get_string
mov si, buffer
mov di, math_plus
call strcmp
jc .plus
jmp mainloop
.plus:
mov si, math_prompt_fnum
call print_string
mov di, buffer
call get_string
mov si, buffer
push stack_end
mov si, math_prompt_num2
call print_string
mov di, buffer
call get_string
pop stack_begin
mov si, di
mov di, buffer
add si, di
call print_string
jmp .done
.done:
ret
Code: Select all
SECTION .bss
stack_begin:
resb 4096
stack_end: