Program name: Difference between revisions

Changed language name from "NASM" to "x86 Assembly" and moved to correct place
(Changed language name from "NASM" to "x86 Assembly" and moved to correct place)
Line 816:
end
</lang>
 
=={{header|NASM assembly}}==
 
==={{header|Linux}}===
Makefile:
<lang make>FORMAT=-f elf
RUN=./
BIN=scriptname
OBJ=scriptname.o
 
all: test
 
test: $(BIN)
$(RUN)$(BIN)
 
$(BIN): $(OBJ)
ld -o $(BIN) $(OBJ)
 
$(OBJ): scriptname.asm
nasm $(FORMAT) -o $(OBJ) scriptname.asm
 
clean:
-rm $(BIN)
-rm $(OBJ)</lang>
 
scriptname.asm:
<lang nasm>bits 32
 
section .data
 
stdout equ 1
 
sys_write equ 4
sys_exit equ 1
 
kernel equ 0x80
 
program db "Program: ", 0
programlen equ $-program
 
nl db "", 10, 0
nllen equ $-nl
 
section .bss
 
scriptname resd 1
scriptnamelen resd 1
 
section .text
 
global _start
 
strlen: ; eax: a string ending in 0
push eax ; cache eax
 
.strloop:
mov bl, byte [eax]
cmp bl, 0
je .strret ; return len if bl == 0
inc eax ; else eax++
jmp .strloop
 
.strret:
pop ebx ; ebx = cached eax
sub eax, ebx ; eax -= ebx
ret ; eax = len
 
_start:
mov eax, esp
add eax, 4
mov eax, [eax]
mov dword [scriptname], eax
 
mov eax, sys_write
mov ebx, stdout
mov ecx, program
mov edx, programlen
int kernel
 
mov dword eax, [scriptname]
call strlen
mov dword [scriptnamelen], eax
 
mov eax, sys_write
mov ebx, stdout
mov dword ecx, [scriptname]
mov dword edx, [scriptnamelen]
int kernel
 
mov eax, sys_write
mov ebx, stdout
mov ecx, nl
mov edx, nllen
int kernel
 
mov eax, sys_exit
mov ebx, 0
int kernel</lang>
 
==={{header|FreeBSD/Mac OS X}}===
Makefile:
<lang make># FreeBSD defaults
 
FORMAT=-f elf
RUN=./
BIN=scriptname
OBJ=scriptname.o
 
# Mac OS X
ifeq ($(shell uname -s),Darwin)
FORMAT=-f macho
MINV=-macosx_version_min 10.6
endif
 
all: test
 
test: $(BIN)
$(RUN)$(BIN)
 
$(BIN): $(OBJ)
ld -o $(BIN) $(MINV) $(OBJ)
 
$(OBJ): scriptname.asm
nasm $(FORMAT) -o $(OBJ) scriptname.asm
 
clean:
-rm $(BIN)
-rm $(OBJ)</lang>
 
scriptname.asm:
<lang nasm>bits 32
 
section .data
 
stdout equ 1
 
sys_write equ 4
sys_exit equ 1
 
kernel equ 0x80
 
program db "Program: ", 0
programlen equ $-program
 
nl db "", 10, 0
nllen equ $-nl
 
section .bss
 
scriptname resd 1
scriptnamelen resd 1
 
section .text
 
global start
 
strlen: ; eax: a string ending in 0
push eax ; cache eax
 
.strloop:
mov bl, byte [eax]
cmp bl, 0
je .strret ; return len if bl == 0
inc eax ; else eax++
jmp .strloop
 
.strret:
pop ebx ; ebx = cached eax
sub eax, ebx ; eax -= ebx
ret ; eax = len
 
start:
mov eax, esp
add eax, 4
mov eax, [eax]
mov dword [scriptname], eax
 
push programlen
push program
push stdout
mov eax, sys_write
sub esp, 4
int kernel
add esp, 4 + 4 * 3
 
mov dword eax, [scriptname]
call strlen
mov dword [scriptnamelen], eax
 
push dword [scriptnamelen]
push dword [scriptname]
push stdout
mov eax, sys_write
sub esp, 4
int kernel
add esp, 4 + 4 * 3
 
push nllen
push nl
push stdout
mov eax, sys_write
sub esp, 4
int kernel
add esp, 4 + 4 * 3
 
push 0
mov eax, sys_exit
sub esp, 4
int kernel</lang>
 
==={{header|Windows}}===
Makefile:
<lang make>FORMAT=-f win32
BIN=scriptname.exe
OBJ=scriptname.obj
RUN=
 
all: test
 
test: $(BIN)
$(RUN)$(BIN)
 
$(BIN): $(OBJ)
golink /fo $(BIN) $(OBJ) /console kernel32.dll Msvcrt.dll
 
$(OBJ): scriptname.asm
nasm $(FORMAT) -o $(OBJ) scriptname.asm
 
clean:
-rm $(BIN)
-rm $(OBJ)</lang>
 
scriptname.asm:
<lang nasm>bits 32
 
section .data
 
program db "Program: ", 0
programlen equ $-program
 
nl db "", 13, 10, 0
nllen equ $-nl
 
stdouthandle equ -11
 
section .bss
 
stdout resd 1
 
charswritten resd 1
 
env resd 1
argc resd 1
argv resd 255
 
scriptname resd 1
scriptnamelen resd 1
 
section .text
 
global Start
extern GetStdHandle
extern __getmainargs
extern WriteConsoleA
extern ExitProcess
 
strlen: ; eax: a string ending in 0
push eax ; cache eax
 
.strloop:
mov bl, byte [eax]
cmp bl, 0
je .strret ; return len if bl == 0
inc eax ; else eax++
jmp .strloop
 
.strret:
pop ebx ; ebx = cached eax
sub eax, ebx ; eax -= ebx
ret ; eax = len
 
Start:
push 0
push env
push argv
push argc
call __getmainargs
mov eax, [argv]
mov eax, [eax]
mov [scriptname], eax
add esp, 4 * 4
 
push stdouthandle
call GetStdHandle
mov [stdout], eax
add esp, 4 * 1
 
push 0
push charswritten
push programlen
push program
push dword [stdout]
call WriteConsoleA
add esp, 4 * 5
 
mov eax, [scriptname]
call strlen
mov [scriptnamelen], eax
 
push 0
push charswritten
push dword [scriptnamelen]
push dword [scriptname]
push dword [stdout]
call WriteConsoleA
add esp, 4 * 5
 
push 0
push charswritten
push nllen
push nl
push dword [stdout]
call WriteConsoleA
add esp, 4 * 5
 
push 0
call ExitProcess</lang>
 
=={{header|Nemerle}}==
Line 1,805 ⟶ 1,478:
appname = fullpath
End If</lang>
 
 
 
=={{header|x86 Assembly}}==
{{Works with|Nasm}}
===Linux===
Makefile:
<lang make>FORMAT=-f elf
RUN=./
BIN=scriptname
OBJ=scriptname.o
 
all: test
 
test: $(BIN)
$(RUN)$(BIN)
 
$(BIN): $(OBJ)
ld -o $(BIN) $(OBJ)
 
$(OBJ): scriptname.asm
nasm $(FORMAT) -o $(OBJ) scriptname.asm
 
clean:
-rm $(BIN)
-rm $(OBJ)</lang>
 
scriptname.asm:
<lang asm>bits 32
 
section .data
 
stdout equ 1
 
sys_write equ 4
sys_exit equ 1
 
kernel equ 0x80
 
program db "Program: ", 0
programlen equ $-program
 
nl db "", 10, 0
nllen equ $-nl
 
section .bss
 
scriptname resd 1
scriptnamelen resd 1
 
section .text
 
global _start
 
strlen: ; eax: a string ending in 0
push eax ; cache eax
 
.strloop:
mov bl, byte [eax]
cmp bl, 0
je .strret ; return len if bl == 0
inc eax ; else eax++
jmp .strloop
 
.strret:
pop ebx ; ebx = cached eax
sub eax, ebx ; eax -= ebx
ret ; eax = len
 
_start:
mov eax, esp
add eax, 4
mov eax, [eax]
mov dword [scriptname], eax
 
mov eax, sys_write
mov ebx, stdout
mov ecx, program
mov edx, programlen
int kernel
 
mov dword eax, [scriptname]
call strlen
mov dword [scriptnamelen], eax
 
mov eax, sys_write
mov ebx, stdout
mov dword ecx, [scriptname]
mov dword edx, [scriptnamelen]
int kernel
 
mov eax, sys_write
mov ebx, stdout
mov ecx, nl
mov edx, nllen
int kernel
 
mov eax, sys_exit
mov ebx, 0
int kernel</lang>
 
===FreeBSD/Mac OS X===
Makefile:
<lang make># FreeBSD defaults
 
FORMAT=-f elf
RUN=./
BIN=scriptname
OBJ=scriptname.o
 
# Mac OS X
ifeq ($(shell uname -s),Darwin)
FORMAT=-f macho
MINV=-macosx_version_min 10.6
endif
 
all: test
 
test: $(BIN)
$(RUN)$(BIN)
 
$(BIN): $(OBJ)
ld -o $(BIN) $(MINV) $(OBJ)
 
$(OBJ): scriptname.asm
nasm $(FORMAT) -o $(OBJ) scriptname.asm
 
clean:
-rm $(BIN)
-rm $(OBJ)</lang>
 
scriptname.asm:
<lang asm>bits 32
 
section .data
 
stdout equ 1
 
sys_write equ 4
sys_exit equ 1
 
kernel equ 0x80
 
program db "Program: ", 0
programlen equ $-program
 
nl db "", 10, 0
nllen equ $-nl
 
section .bss
 
scriptname resd 1
scriptnamelen resd 1
 
section .text
 
global start
 
strlen: ; eax: a string ending in 0
push eax ; cache eax
 
.strloop:
mov bl, byte [eax]
cmp bl, 0
je .strret ; return len if bl == 0
inc eax ; else eax++
jmp .strloop
 
.strret:
pop ebx ; ebx = cached eax
sub eax, ebx ; eax -= ebx
ret ; eax = len
 
start:
mov eax, esp
add eax, 4
mov eax, [eax]
mov dword [scriptname], eax
 
push programlen
push program
push stdout
mov eax, sys_write
sub esp, 4
int kernel
add esp, 4 + 4 * 3
 
mov dword eax, [scriptname]
call strlen
mov dword [scriptnamelen], eax
 
push dword [scriptnamelen]
push dword [scriptname]
push stdout
mov eax, sys_write
sub esp, 4
int kernel
add esp, 4 + 4 * 3
 
push nllen
push nl
push stdout
mov eax, sys_write
sub esp, 4
int kernel
add esp, 4 + 4 * 3
 
push 0
mov eax, sys_exit
sub esp, 4
int kernel</lang>
 
===Windows===
Makefile:
<lang make>FORMAT=-f win32
BIN=scriptname.exe
OBJ=scriptname.obj
RUN=
 
all: test
 
test: $(BIN)
$(RUN)$(BIN)
 
$(BIN): $(OBJ)
golink /fo $(BIN) $(OBJ) /console kernel32.dll Msvcrt.dll
 
$(OBJ): scriptname.asm
nasm $(FORMAT) -o $(OBJ) scriptname.asm
 
clean:
-rm $(BIN)
-rm $(OBJ)</lang>
 
scriptname.asm:
<lang asm>bits 32
 
section .data
 
program db "Program: ", 0
programlen equ $-program
 
nl db "", 13, 10, 0
nllen equ $-nl
 
stdouthandle equ -11
 
section .bss
 
stdout resd 1
 
charswritten resd 1
 
env resd 1
argc resd 1
argv resd 255
 
scriptname resd 1
scriptnamelen resd 1
 
section .text
 
global Start
extern GetStdHandle
extern __getmainargs
extern WriteConsoleA
extern ExitProcess
 
strlen: ; eax: a string ending in 0
push eax ; cache eax
 
.strloop:
mov bl, byte [eax]
cmp bl, 0
je .strret ; return len if bl == 0
inc eax ; else eax++
jmp .strloop
 
.strret:
pop ebx ; ebx = cached eax
sub eax, ebx ; eax -= ebx
ret ; eax = len
 
Start:
push 0
push env
push argv
push argc
call __getmainargs
mov eax, [argv]
mov eax, [eax]
mov [scriptname], eax
add esp, 4 * 4
 
push stdouthandle
call GetStdHandle
mov [stdout], eax
add esp, 4 * 1
 
push 0
push charswritten
push programlen
push program
push dword [stdout]
call WriteConsoleA
add esp, 4 * 5
 
mov eax, [scriptname]
call strlen
mov [scriptnamelen], eax
 
push 0
push charswritten
push dword [scriptnamelen]
push dword [scriptname]
push dword [stdout]
call WriteConsoleA
add esp, 4 * 5
 
push 0
push charswritten
push nllen
push nl
push dword [stdout]
call WriteConsoleA
add esp, 4 * 5
 
push 0
call ExitProcess</lang>
 
{{omit from|AWK|With gawk, mawk, or nawk: ARGV[0] reports the name of the awk interpreter, not the name of the awk script. There is no variable nor shell command that provides the name of the awk script.}}