checking in all chnages, including todays play with gnu-as
This commit is contained in:
BIN
bootloader1/boot.bin
Normal file
BIN
bootloader1/boot.bin
Normal file
Binary file not shown.
BIN
bootloader1/bootsect.img
Normal file
BIN
bootloader1/bootsect.img
Normal file
Binary file not shown.
BIN
bootloader1/floppy.img
Normal file
BIN
bootloader1/floppy.img
Normal file
Binary file not shown.
BIN
counter/counter
Executable file
BIN
counter/counter
Executable file
Binary file not shown.
BIN
counter/counter.o
Normal file
BIN
counter/counter.o
Normal file
Binary file not shown.
BIN
counter2/counter
Executable file
BIN
counter2/counter
Executable file
Binary file not shown.
BIN
counter2/counter.o
Normal file
BIN
counter2/counter.o
Normal file
Binary file not shown.
BIN
gnu-asm/hello1/hello
Executable file
BIN
gnu-asm/hello1/hello
Executable file
Binary file not shown.
BIN
gnu-asm/hello1/hello.o
Normal file
BIN
gnu-asm/hello1/hello.o
Normal file
Binary file not shown.
93
gnu-asm/hello1/hello.s
Normal file
93
gnu-asm/hello1/hello.s
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
# hello.s
|
||||||
|
#
|
||||||
|
# Ask for the user's name, then print:
|
||||||
|
# Hello <name>
|
||||||
|
# five times.
|
||||||
|
|
||||||
|
.section .rodata
|
||||||
|
|
||||||
|
prompt:
|
||||||
|
.ascii "What is your name? "
|
||||||
|
prompt_end:
|
||||||
|
|
||||||
|
hello:
|
||||||
|
.ascii "Hello "
|
||||||
|
hello_end:
|
||||||
|
|
||||||
|
newline:
|
||||||
|
.byte 10 # ASCII newline: '\n'
|
||||||
|
|
||||||
|
|
||||||
|
.section .bss
|
||||||
|
|
||||||
|
.align 16
|
||||||
|
name_buf:
|
||||||
|
.skip 64 # Reserve 64 bytes for the name
|
||||||
|
|
||||||
|
|
||||||
|
.section .text
|
||||||
|
|
||||||
|
.global _start
|
||||||
|
|
||||||
|
_start:
|
||||||
|
# write(STDOUT, prompt, prompt_length)
|
||||||
|
mov $1, %rax # syscall 1: write
|
||||||
|
mov $1, %rdi # file descriptor 1: stdout
|
||||||
|
lea prompt(%rip), %rsi # address of prompt
|
||||||
|
mov $(prompt_end - prompt), %rdx
|
||||||
|
syscall
|
||||||
|
|
||||||
|
# read(STDIN, name_buf, 63)
|
||||||
|
xor %rax, %rax # syscall 0: read
|
||||||
|
xor %rdi, %rdi # file descriptor 0: stdin
|
||||||
|
lea name_buf(%rip), %rsi
|
||||||
|
mov $63, %rdx
|
||||||
|
syscall
|
||||||
|
|
||||||
|
# RAX contains the number of bytes read.
|
||||||
|
# Exit if read returned zero or an error.
|
||||||
|
test %rax, %rax
|
||||||
|
jle exit
|
||||||
|
|
||||||
|
# Save the length of the name in R12.
|
||||||
|
mov %rax, %r12
|
||||||
|
|
||||||
|
# Remove the trailing newline entered by the user.
|
||||||
|
lea name_buf(%rip), %rbx
|
||||||
|
cmpb $10, -1(%rbx,%r12)
|
||||||
|
jne repeat_setup
|
||||||
|
dec %r12
|
||||||
|
|
||||||
|
repeat_setup:
|
||||||
|
mov $5, %r13 # Loop counter
|
||||||
|
|
||||||
|
repeat_loop:
|
||||||
|
# Write "Hello "
|
||||||
|
mov $1, %rax
|
||||||
|
mov $1, %rdi
|
||||||
|
lea hello(%rip), %rsi
|
||||||
|
mov $(hello_end - hello), %rdx
|
||||||
|
syscall
|
||||||
|
|
||||||
|
# Write the user's name
|
||||||
|
mov $1, %rax
|
||||||
|
mov $1, %rdi
|
||||||
|
lea name_buf(%rip), %rsi
|
||||||
|
mov %r12, %rdx
|
||||||
|
syscall
|
||||||
|
|
||||||
|
# Write newline
|
||||||
|
mov $1, %rax
|
||||||
|
mov $1, %rdi
|
||||||
|
lea newline(%rip), %rsi
|
||||||
|
mov $1, %rdx
|
||||||
|
syscall
|
||||||
|
|
||||||
|
dec %r13
|
||||||
|
jne repeat_loop
|
||||||
|
|
||||||
|
exit:
|
||||||
|
# exit(0)
|
||||||
|
mov $60, %rax # syscall 60: exit
|
||||||
|
xor %rdi, %rdi # exit status 0
|
||||||
|
syscall
|
||||||
BIN
gnu-asm/hello1/hello.stripped
Executable file
BIN
gnu-asm/hello1/hello.stripped
Executable file
Binary file not shown.
7
gnu-asm/hello1/run.sh
Executable file
7
gnu-asm/hello1/run.sh
Executable file
@@ -0,0 +1,7 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
as --64 -o hello.o hello.s
|
||||||
|
ld -o hello hello.o
|
||||||
|
cp hello hello.stripped
|
||||||
|
strip --strip-all hello.stripped
|
||||||
|
./hello.stripped
|
||||||
|
|
||||||
Reference in New Issue
Block a user