Why is the subtraction in _FN not working? It seems to be adding a constant large number to what I want the result to be. Not sure why. It is printing huge numbers, but the registers hold the correct values, so I am not sure why it is doing this.
I was wondering if there is something special with subl, or if the registers are actually holding memory locations or something.
// Pgm to
// S. Renk 11/01
// *****************************************
// **** ****
// *****************************************
.text
.globl _FN
_FN: //
// save old base ptr & get space for local vars
pushl %ebp
movl %esp,%ebp
// create local vars
subl $12, %esp
movl 12(%ebp),%ecx
movl 8(%ebp),%ebx
pushl %ecx
pushl $FMT2
call _printf
addl $8,%esp
pushl %ebx
pushl $FMT2
call _printf
addl $8,%esp
subl %ebx,%ecx
pushl %ecx
pushl $FMT_INT
call _printf
addl $8,%esp
// function body goes here
END: // exit & return
// movl -4(%ebp),%eax
leave
ret
// *******************************************
// *********** MAIN ************
// *******************************************
PROMPT:
.ascii "enter a number: \0"
FMT_INT:
.ascii "%d\0"
FMT2:
.ascii "My value is %d\n\0"
TEST:
.ascii "PRINT\n\0"
ANSWER:
.ascii "The answer is: %d\0"
.globl _main
// void main()
_main:
pushl %ebp # save old frame ptr
movl %esp,%ebp # set new frame ptr & save loal var space
// create local variable space
subl $8, %esp
// main body here
//prompts the user for the number to divide
pushl $PROMPT
call _printf
addl $4,%esp
//Create D1 Variable
leal -4(%ebp),%ebx #puts the address of D1 in ebx
//takes in the number to divide
pushl %ebx
pushl $FMT_INT
call _scanf
addl $8,%esp
//prompts the user for the number to divide by
pushl $PROMPT
call _printf
addl $4,%esp
//Create D2 Variable
leal -8(%ebp),%ecx #puts the address of D2 in ecx
//takes in the number to divide by
pushl %ecx
pushl $FMT_INT
call _scanf
addl $8,%esp
//tests to make sure variables are where they need to be
pushl -4(%ebp)
pushl $FMT2
call _printf
addl $8,%esp
pushl -8(%ebp)
pushl $FMT2
call _printf
addl $8,%esp
call _FN
// return
leave
ret