hello_slices
This commit is contained in:
@ -9,7 +9,7 @@ extern WriteConsoleA
|
|||||||
; Data section
|
; Data section
|
||||||
section .data
|
section .data
|
||||||
message db "Hello, NASM!", 13, 10, 0 ; String with CRLF and null terminator
|
message db "Hello, NASM!", 13, 10, 0 ; String with CRLF and null terminator
|
||||||
message_len equ $ - message ; Calculate string length
|
message_len equ $ - message ; Calculate string length
|
||||||
|
|
||||||
; Code section
|
; Code section
|
||||||
section .text
|
section .text
|
||||||
|
81
code/asm/hello_slices.asm
Normal file
81
code/asm/hello_slices.asm
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
; Hello Slices!
|
||||||
|
|
||||||
|
%define marg
|
||||||
|
|
||||||
|
%define rcounter_32 ecx
|
||||||
|
|
||||||
|
%define reg8_32 r8d
|
||||||
|
|
||||||
|
%define raccumulator rax
|
||||||
|
%define rcounter rcx
|
||||||
|
%define rdata rdx
|
||||||
|
%define rstack_ptr rsp
|
||||||
|
%define rstack_base_ptr rbp
|
||||||
|
|
||||||
|
%define reg9 r9
|
||||||
|
|
||||||
|
%define MS_STD_OUTPUT_HANDLE 11
|
||||||
|
|
||||||
|
struc Slice_Byte
|
||||||
|
.ptr: resq 1
|
||||||
|
.len: resq 1
|
||||||
|
endstruc
|
||||||
|
|
||||||
|
struc Slice_Str8
|
||||||
|
.ptr: resq 1
|
||||||
|
.len: resq 1
|
||||||
|
endstruc
|
||||||
|
|
||||||
|
; Usage: lit %1: <slice_label> %2: <utf-8 literal>
|
||||||
|
%macro lit 2
|
||||||
|
lit_ %+ %1: db %2
|
||||||
|
lit_ %+ %1 %+ _len: equ $ - (lit_ %+ %1)
|
||||||
|
%endmacro
|
||||||
|
|
||||||
|
BITS 64 ; Explicitly specify 64-bit mode
|
||||||
|
DEFAULT REL ; Use RIP-relative addressing by default
|
||||||
|
|
||||||
|
; kernel32.lib
|
||||||
|
extern GetStdHandle
|
||||||
|
extern WriteConsoleA
|
||||||
|
|
||||||
|
section .data
|
||||||
|
std_out_hndl dq 0
|
||||||
|
|
||||||
|
section .lits progbits noexec nowrite
|
||||||
|
lit hello_msg, `Hello Slices\n`
|
||||||
|
|
||||||
|
section .text
|
||||||
|
global main
|
||||||
|
|
||||||
|
%define wapi_shadow_width 48
|
||||||
|
%macro wapi_shadow_space 0
|
||||||
|
push rstack_base_ptr
|
||||||
|
mov rstack_base_ptr, rstack_ptr
|
||||||
|
sub rstack_ptr, wapi_shadow_width
|
||||||
|
%endmacro
|
||||||
|
%define wapi_arg4_offset 28
|
||||||
|
%define wapi_arg5_offset 32
|
||||||
|
|
||||||
|
%define wapi_write_console_written_chars reg9
|
||||||
|
%macro wapi_write_console 2
|
||||||
|
mov rcounter,[%1] ; Console Handle
|
||||||
|
lea rdata, [%2] ; Slice_Str8.Ptr
|
||||||
|
mov reg8_32, %2 %+ _len ; Slice_Str8.Len
|
||||||
|
lea reg9, [rstack_ptr + wapi_arg4_offset] ; Written chars
|
||||||
|
mov qword [rstack_ptr + wapi_arg5_offset], 0 ; Reserved (must be 0)
|
||||||
|
call WriteConsoleA
|
||||||
|
%endmacro
|
||||||
|
|
||||||
|
main:
|
||||||
|
wapi_shadow_space
|
||||||
|
|
||||||
|
; Setup stdout handle
|
||||||
|
mov rcounter_32, -MS_STD_OUTPUT_HANDLE
|
||||||
|
call GetStdHandle
|
||||||
|
mov [std_out_hndl], raccumulator
|
||||||
|
|
||||||
|
wapi_write_console std_out_hndl, lit_hello_msg
|
||||||
|
|
||||||
|
leave
|
||||||
|
ret
|
@ -1,3 +1,3 @@
|
|||||||
package asmduff
|
package asmduff
|
||||||
|
|
||||||
import
|
// import
|
||||||
|
@ -1,2 +1,75 @@
|
|||||||
$nasm = 'nasm'
|
$ps1_devshell = join-path $PSScriptRoot 'helpers/devshell.ps1'
|
||||||
& $nasm -help
|
. $ps1_devshell -arch amd64
|
||||||
|
$path_root = split-path -Path $PSScriptRoot -Parent
|
||||||
|
$path_build = join-path $path_root 'build'
|
||||||
|
$path_code = join-path $path_root 'code'
|
||||||
|
$path_asm = join-path $path_code 'asm'
|
||||||
|
$path_toolchain = join-path $path_root 'toolchain'
|
||||||
|
$path_radlink = join-path $path_toolchain 'radlink'
|
||||||
|
|
||||||
|
if ((test-path $path_build) -eq $false) {
|
||||||
|
new-item -itemtype directory -path $path_build
|
||||||
|
}
|
||||||
|
|
||||||
|
$hello_nasm = join-path $path_asm 'hello_nasm.asm'
|
||||||
|
$listing = join-path $path_build 'hello_nasm.list'
|
||||||
|
$link_obj = join-path $path_build 'hello_nasm.o'
|
||||||
|
$exe = join-path $path_build 'hello_nasm.exe'
|
||||||
|
|
||||||
|
$nasm = 'nasm'
|
||||||
|
$radlink = join-path $path_radlink 'radlink.exe'
|
||||||
|
|
||||||
|
push-location $path_root
|
||||||
|
$f_assemble_only = '-a'
|
||||||
|
$f_bin_fmt_coff = '-f coff'
|
||||||
|
$f_bin_fmt_win64 = '-f win64'
|
||||||
|
$f_debug = '-g'
|
||||||
|
$f_debug_fmt_win64 = '-g cv8'
|
||||||
|
$f_dmacro = '-Dmacro='
|
||||||
|
$f_Ipath = '-Ipath '
|
||||||
|
$f_listing = '-l'
|
||||||
|
$f_preprocess_only = '-E'
|
||||||
|
$f_optimize_none = '-O0'
|
||||||
|
$f_optimize_min = '-O1'
|
||||||
|
$f_optimize_multi = '-Ox'
|
||||||
|
$f_optimize_multi_disp = '-Ov'
|
||||||
|
$f_outfile = '-o '
|
||||||
|
$f_warnings_as_errors = '-Werror'
|
||||||
|
$args = @(
|
||||||
|
$hello_nasm,
|
||||||
|
$f_optimize_none,
|
||||||
|
$f_bin_fmt_win64,
|
||||||
|
$f_debug_fmt_win64,
|
||||||
|
($f_listing + $listing),
|
||||||
|
($f_outfile + $link_obj)
|
||||||
|
)
|
||||||
|
& $nasm $args
|
||||||
|
|
||||||
|
$lib_kernel32 = 'kernel32.lib'
|
||||||
|
$lib_msvcrt = 'msvcrt.lib'
|
||||||
|
|
||||||
|
$link = 'link.exe'
|
||||||
|
|
||||||
|
$link_debug = '/DEBUG:'
|
||||||
|
$link_entrypoint = '/ENTRY:'
|
||||||
|
$link_library = '/'
|
||||||
|
$link_outfile = '/OUT:'
|
||||||
|
$link_win_machine_64 = '/MACHINE:X64'
|
||||||
|
$link_win_subsystem_console = '/SUBSYSTEM:CONSOLE'
|
||||||
|
$link_win_subsystem_windows = '/SUBSYSTEM:WINDOWS'
|
||||||
|
$rad_debug = '/RAD_DEBUG'
|
||||||
|
$rad_debug_name = '/RAD_DEBUG_NAME:'
|
||||||
|
$rad_large_pages = '/RAD_LARGE_PAGES:'
|
||||||
|
$args = @(
|
||||||
|
$rad_debug,
|
||||||
|
# ($link_debug + 'FULL'),
|
||||||
|
$link_win_machine_64,
|
||||||
|
$link_win_subsystem_console,
|
||||||
|
$lib_kernel32,
|
||||||
|
# $lib_msvcrt,
|
||||||
|
($link_entrypoint + 'main'),
|
||||||
|
($link_outfile + $exe),
|
||||||
|
$link_obj
|
||||||
|
)
|
||||||
|
& $radlink $args
|
||||||
|
pop-location
|
||||||
|
76
scripts/build_hello_slices.ps1
Normal file
76
scripts/build_hello_slices.ps1
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
$ps1_devshell = join-path $PSScriptRoot 'helpers/devshell.ps1'
|
||||||
|
. $ps1_devshell -arch amd64
|
||||||
|
$path_root = split-path -Path $PSScriptRoot -Parent
|
||||||
|
$path_build = join-path $path_root 'build'
|
||||||
|
$path_code = join-path $path_root 'code'
|
||||||
|
$path_asm = join-path $path_code 'asm'
|
||||||
|
$path_toolchain = join-path $path_root 'toolchain'
|
||||||
|
$path_radlink = join-path $path_toolchain 'radlink'
|
||||||
|
|
||||||
|
if ((test-path $path_build) -eq $false) {
|
||||||
|
new-item -itemtype directory -path $path_build
|
||||||
|
}
|
||||||
|
|
||||||
|
$hello_nasm = join-path $path_asm 'hello_slices.asm'
|
||||||
|
$listing = join-path $path_build 'hello_slices.list'
|
||||||
|
$link_obj = join-path $path_build 'hello_slices.o'
|
||||||
|
$exe = join-path $path_build 'hello_slices.exe'
|
||||||
|
|
||||||
|
$nasm = 'nasm'
|
||||||
|
$radlink = join-path $path_radlink 'radlink.exe'
|
||||||
|
|
||||||
|
push-location $path_root
|
||||||
|
$f_assemble_only = '-a'
|
||||||
|
$f_bin_fmt_coff = '-f coff'
|
||||||
|
$f_bin_fmt_win64 = '-f win64'
|
||||||
|
$f_debug = '-g'
|
||||||
|
$f_debug_fmt_win64 = '-g cv8'
|
||||||
|
$f_dmacro = '-Dmacro='
|
||||||
|
$f_Ipath = '-Ipath '
|
||||||
|
$f_listing = '-l'
|
||||||
|
$f_preprocess_only = '-E'
|
||||||
|
$f_optimize_none = '-O0'
|
||||||
|
$f_optimize_min = '-O1'
|
||||||
|
$f_optimize_multi = '-Ox'
|
||||||
|
$f_optimize_multi_disp = '-Ov'
|
||||||
|
$f_outfile = '-o '
|
||||||
|
$f_warnings_as_errors = '-Werror'
|
||||||
|
$args = @(
|
||||||
|
$hello_nasm,
|
||||||
|
$f_optimize_none,
|
||||||
|
# $f_preprocess_only,
|
||||||
|
$f_bin_fmt_win64,
|
||||||
|
$f_debug_fmt_win64,
|
||||||
|
($f_listing + $listing),
|
||||||
|
($f_outfile + $link_obj)
|
||||||
|
)
|
||||||
|
& $nasm $args
|
||||||
|
|
||||||
|
$lib_kernel32 = 'kernel32.lib'
|
||||||
|
$lib_msvcrt = 'msvcrt.lib'
|
||||||
|
|
||||||
|
$link = 'link.exe'
|
||||||
|
|
||||||
|
$link_debug = '/DEBUG:'
|
||||||
|
$link_entrypoint = '/ENTRY:'
|
||||||
|
$link_library = '/'
|
||||||
|
$link_outfile = '/OUT:'
|
||||||
|
$link_win_machine_64 = '/MACHINE:X64'
|
||||||
|
$link_win_subsystem_console = '/SUBSYSTEM:CONSOLE'
|
||||||
|
$link_win_subsystem_windows = '/SUBSYSTEM:WINDOWS'
|
||||||
|
$rad_debug = '/RAD_DEBUG'
|
||||||
|
$rad_debug_name = '/RAD_DEBUG_NAME:'
|
||||||
|
$rad_large_pages = '/RAD_LARGE_PAGES:'
|
||||||
|
$args = @(
|
||||||
|
$rad_debug,
|
||||||
|
# ($link_debug + 'FULL'),
|
||||||
|
$link_win_machine_64,
|
||||||
|
$link_win_subsystem_console,
|
||||||
|
$lib_kernel32,
|
||||||
|
# $lib_msvcrt,
|
||||||
|
($link_entrypoint + 'main'),
|
||||||
|
($link_outfile + $exe),
|
||||||
|
$link_obj
|
||||||
|
)
|
||||||
|
& $radlink $args
|
||||||
|
pop-location
|
28
scripts/helpers/devshell.ps1
Normal file
28
scripts/helpers/devshell.ps1
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
if ($env:VCINSTALLDIR) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
$ErrorActionPreference = "Stop"
|
||||||
|
|
||||||
|
# Use vswhere to find the latest Visual Studio installation
|
||||||
|
$vswhere_out = & "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -latest -property installationPath
|
||||||
|
if ($null -eq $vswhere_out) {
|
||||||
|
Write-Host "ERROR: Visual Studio installation not found"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Find Launch-VsDevShell.ps1 in the Visual Studio installation
|
||||||
|
$vs_path = $vswhere_out
|
||||||
|
$vs_devshell = Join-Path $vs_path "\Common7\Tools\Launch-VsDevShell.ps1"
|
||||||
|
|
||||||
|
if ( -not (Test-Path $vs_devshell) ) {
|
||||||
|
Write-Host "ERROR: Launch-VsDevShell.ps1 not found in Visual Studio installation"
|
||||||
|
Write-Host Tested path: $vs_devshell
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Launch the Visual Studio Developer Shell
|
||||||
|
Push-Location
|
||||||
|
write-host @args
|
||||||
|
& $vs_devshell @args
|
||||||
|
Pop-Location
|
BIN
toolchain/radlink/radlink.exe
Normal file
BIN
toolchain/radlink/radlink.exe
Normal file
Binary file not shown.
BIN
toolchain/radlink/radlink.pdb
Normal file
BIN
toolchain/radlink/radlink.pdb
Normal file
Binary file not shown.
@ -4,3 +4,10 @@
|
|||||||
|
|
||||||
Repo: https://github.com/Ed94/gencpp.git
|
Repo: https://github.com/Ed94/gencpp.git
|
||||||
Commit: 685bba36d5ed64b48908c950fbbb7f1dbb297120
|
Commit: 685bba36d5ed64b48908c950fbbb7f1dbb297120
|
||||||
|
|
||||||
|
## NASM
|
||||||
|
|
||||||
|
Version: 2.16.03
|
||||||
|
Installed Via: scoop
|
||||||
|
|
||||||
|
## RAD Linker
|
||||||
|
Reference in New Issue
Block a user