Old nasm code revisited

Code junkies hangout here

Moderators: ChrisThornett, LXF moderators

Old nasm code revisited

Postby pk_fox » Wed Jan 21, 2015 2:35 pm

Hi all, I've just resurrected some nasm code I modelled from a Mike Saunders tutorial a few years back and whilst it still works it produces an output file name of weird characters, If I assemble the code and run it like so , myexec pete.txt it used to produce a file called pete.txt with a 1000 lines of Hello World!, it still writes the lines of text ok but the file name is something like ???$???N, the only difference I can think of is I'm running the programme on Debian 64 bit in a virtual machine

Code: Select all
section .data
hello db ' ) Hello, world!',10 ;
helloLen equ $ - hello ;

section .bss
loopctr resd 1
looplimit resd 1

section .text
global main
main:
mov dword [loopctr],0
mov dword [looplimit],1000

pop ebx ; argc (argument count)
pop ebx ; argv[0] (argument 0, the program name)
pop ebx ; The first real arg, a filename
mov eax,8 ; The syscall number for creat() (we already have the filename in ebx)
mov ecx, 0x0700
int 80h ; Call the kernel ; Now we have a file descriptor in eax
test eax,eax ; Lets make sure the file descriptor is valid
js skipWrite ; If the file descriptor has the sign flag ; (which means it's less than 0) there was an oops, ; so skip the writing. Otherwise call the filewrite "procedure"
call fileWrite
skipWrite:
mov ebx,eax ; If there was an error, save the errno in ebx
mov eax,1 ; Put the exit syscall number in eax
int 80h ; Bail out ;

fileWrite:
mov ebx,eax ; sys_creat returned file descriptor into eax, now move into ebx
mov eax,4 ; sys_write ebx is already set up
mov ecx,hello ; We are putting the ADDRESS of hello in ecx
mov edx,helloLen ; This is the VALUE of helloLen because it's a constant (defined with equ)
jmp myloop

myloop:
push eax
int 80h
pop eax
inc dword [loopctr]
push edx
mov edx,[loopctr]
cmp dword edx,[looplimit]
pop edx
je end
jmp myloop

; endp fileWrite

end:
mov eax,6 ; sys_close (ebx already contains file descriptor)
int 80h
ret


any ideas ? Mike are you still around ?
We can't stop here, this is bat country. Hunter S Thompson RIP.
User avatar
pk_fox
LXF regular
 
Posts: 299
Joined: Wed Apr 13, 2005 1:38 pm
Location: Surrey, UK

Re: Old nasm code revisited

Postby Ram » Wed Jan 21, 2015 6:45 pm

You'll have to visit him at his new hang out. Linux Voice

lubuntu LXDE 13.10 running on AMD Phenom II*4; ASUS Crosshair III Formula MB; 4 GB Ram.....
User avatar
Ram
LXF regular
 
Posts: 1689
Joined: Thu Apr 07, 2005 9:44 pm
Location: Guisborough


Return to Programming

Who is online

Users browsing this forum: No registered users and 1 guest

cron