I have been using MASM to write programs for over 10 years so I am not new to this, what I am new to is Linux. Feel like a newb all over again.
Before anyone says just link and use the C functions, I will get to that after I understand what "goes on down here" in Linux.
So to create a buffer dynamically, we need to call sys_brk with ebx = 0 to get the address of the end of our data section. Then we call it again with a size. So, why does this still work with the second call to sys_brk commented out?
SECTION .bss
New_Break resd 1
lpBuffer resb 12
Org_Break resd 1
SECTION .text
global _start
_start:
mov ebx, 0
mov eax, sys_brk
int 80H
mov [New_Break], eax
;~ push eax
push eax
call PrintNum
;~ pop eax
;~
;~ add eax, 5
;~ mov ebx, eax
;~ mov eax, sys_brk
;~ int 80H
;~ mov edi, eax
;~ push eax
;~ call PrintNum
mov edx, [New_Break]
mov dword [ecx], "ABCD"
mov byte [ecx +4], 10
mov edx, 5
mov eax, sys_write
mov ebx, stdout
int 80H
mov ebx, Org_Break
mov eax, sys_brk
int 80H
push eax
call PrintNum
Exit:
mov eax, sys_exit
xor ebx, ebx
int 80H
and the output:
gunner@LinuxDevel ~/Desktop/asm/projects/memalloc $ ./memalloc
136335360
ABCD
136335360