malloc in assembly 8086 -
i need receive input user , required use malloc init buffer first. can't find example online.
this buffer:
section .bss buffer: resb 80 ;store input
how done? ok? (it compiles don't think works...)
push 80 push buffer call malloc add esp, 8
or maybe this? (this doesn't compile)
push 80 push buffer call malloc add esp, 8 mov buffer, [eax]
the thing when give buffer input 0, prints 2608 instead of 48 ascii value should print.
input 1 -> gives 2609 accordingly. guess somehow buffer has values it's not supposed have.
this fgets part (it works ok)
push dword [stdin] ;fgets need 3 param push dword 80 ;max lenght push dword buffer ;input buffer call fgets add esp, 12 ;remove 3 push stuck
and print part:
push dword [buffer] ;push string stuck push int_format ; int_format:db "%d", 10, 0 call printf add esp, 8 ;remove pushed argument
malloc has 1 dword
parameter, size in bytes allocate, should called:
push <size> call malloc add esp, 4 ; eax points allocated buffer of requested size mov [eax], ebx ; set first 4 bytes of buffer ebx (etc...)
Comments
Post a Comment