summary refs log tree commit diff
diff options
context:
space:
mode:
authorIrene Knapp <ireneista@irenes.space>2025-10-05 22:07:40 -0700
committerIrene Knapp <ireneista@irenes.space>2025-10-05 22:07:40 -0700
commit14d71a07dafa023ba83c2bdc6837d4ecc9de12ba (patch)
treeb4bb3a997ed1149ae63670c3f62ea218291e2776
parent8f94834e451cf7ae7cccb5522562b3dea3754039 (diff)
hello works! yay
Force-Push: yes
Change-Id: I6c70991d16bd27da2b75ee0666203f043714a685
-rw-r--r--asm-notes.txt77
-rw-r--r--exit-code.gnu.asm (renamed from exit-code.S)0
-rw-r--r--hello.asm (renamed from quine.asm)67
3 files changed, 108 insertions, 36 deletions
diff --git a/asm-notes.txt b/asm-notes.txt
new file mode 100644
index 0000000..03bf335
--- /dev/null
+++ b/asm-notes.txt
@@ -0,0 +1,77 @@
+
+
+
+    ; opcode c7 is Ev, Iz. c6 is Eb, Ib
+    ; Eb: ModR/M to follow, byte
+    ; consider 1100 011w : 11 000 reg : imm
+    ; also consider 1011 w reg : imm for bytes
+
+32-bit target, 8-bit source
+  match =eax?, target
+    db 0xB8
+    dd source
+  else match =edi?, target
+    db 0xBF
+    dd source
+
+64-bit target, 32-bit source
+  match =rax?, target            ; mov rax, 0x1234
+    db 0x48, 0xC7, 0xC0
+    dd source
+;   48                           eAX REX.W prefix
+;                                    (DEC is the 32-bit meaning, ignore it)
+;                                    eAX -> register identifier,
+;                                           width depends on operand
+;                                    REX.W -> set 64-bit operand mode
+;           c7                    Grp 11^1A - MOV Ev, Iz
+;                                    immediate to register
+;                                    1A -> bits 5,4,3 of ModR/M are opcode
+;                                          extension
+;                                    E -> modR/M byte to follow for operand
+;                                    v -> word of appropriate size
+;                                    I -> immediate data
+;                                    z -> 32-bit operand
+;              c0                ModR/M byte
+;              0b11000000
+;                11               mod: always 11
+;                  000            op/reg: Mov Ev, Iz
+;                     00x         w absent
+;                       0         w (ignored)
+
+
+
+  match =rdi, target             ; mov rdi, 0x1234
+    db 0x48, 0xC7, 0xC7
+    dd source
+;   7:   48 c7 c7 2a 00 00 00    mov    $0x2a,%rdi
+;   48                           eAX REX.W prefix
+;                                    (DEC is the 32-bit meaning, ignore it)
+;           c7                   Grp 11^1A - MOV Ev, Iz
+;                                    immediate to register
+;                                    1A -> bits 5,4,3 of ModR/M are opcode
+;                                          extension
+;                                    Ev -> ModR/M to follow for 32-bit operand
+;                                    Iz -> Immediate data, 32-bits
+;              c7                ModR/M byte
+;              0b11000111
+;                11               mod: always 11
+;                  000            op/reg: Mov Ev, Iz
+;                     11x         w present
+;                       1         w true; use EDI
+
+
+
+64-bit target, 64-bi source
+
+  match =rdi, target             ; mov rdi, 0x1234
+    db 0x48, 0xB8, 0x38
+    dq source
+
+  match =rsi, target
+    db 0x48, 0xB8, 0x30
+    dq source
+    ; opcode c7 is Ev, Iz. c6 is Eb, Ib
+    ; Eb: ModR/M to follow, byte
+    ; consider 1100 011w : 11 000 reg : imm
+    ; also consider 1011 w reg : imm for bytes
+
diff --git a/exit-code.S b/exit-code.gnu.asm
index 4c723e8..4c723e8 100644
--- a/exit-code.S
+++ b/exit-code.gnu.asm
diff --git a/quine.asm b/hello.asm
index 9823d93..ed5dd57 100644
--- a/quine.asm
+++ b/hello.asm
@@ -1,4 +1,4 @@
-; fasmg quine.asm quine
+; fasmg hello.asm hello && chmod 755 hello && ./hello; echo $?
 
 macro mov.d target, source
   match =eax?, target
@@ -9,47 +9,32 @@ macro mov.d target, source
     dd source
   else match =rax?, target
     db 0x48, 0xC7, 0xC0
-;   48                           eAX REX.W prefix
-;                                    (DEC is the 32-bit meaning, ignore it)
-;                                    eAX -> register identifier,
-;                                           width depends on operand
-;                                    REX.W -> set 64-bit operand mode
-;           c7                    Grp 11^1A - MOV Ev, Iz
-;                                    immediate to register
-;                                    1A -> bits 5,4,3 of ModR/M are opcode
-;                                          extension
-;                                    E -> modR/M byte to follow for operand
-;                                    v -> word of appropriate size
-;                                    I -> immediate data
-;                                    z -> 32-bit operand
-;              c0                ModR/M byte
-;              0b11000000
-;                11               mod: always 11
-;                  000            op/reg: Mov Ev, Iz
-;                     00x         w absent
-;                       0         w (ignored)
     dd source
   else match =rdi, target
     db 0x48, 0xC7, 0xC7
-;   7:   48 c7 c7 2a 00 00 00    mov    $0x2a,%rdi
-;   48                           eAX REX.W prefix
-;                                    (DEC is the 32-bit meaning, ignore it)
-;           c7                   Grp 11^1A - MOV Ev, Iz
-;                                    immediate to register
-;                                    1A -> bits 5,4,3 of ModR/M are opcode
-;                                          extension
-;                                    Ev -> ModR/M to follow for 32-bit operand
-;                                    Iz -> Immediate data, 32-bits
-;              c7                ModR/M byte
-;              0b11000111
-;                11               mod: always 11
-;                  000            op/reg: Mov Ev, Iz
-;                     11x         w present
-;                       1         w true; use EDI
     dd source
+  else
+    assert 0
   end match
 end macro
 
+
+macro mov.q target, source
+  match =rdi, target
+    db 0x48, 0xBF
+    dq source
+  else match =rsi, target
+    db 0x48, 0xBE
+    dq source
+  else match =rdx, target
+    db 0x48, 0xBA
+    dq source
+  else
+    assert 0
+  end match
+end macro
+
+
 macro syscall
   db 0x0F, 0x05
 ;        0f                      two-byte escape
@@ -101,9 +86,19 @@ program_header:
 program_header_entry_size = $ - program_header
 
 _start:
+  mov.d eax, 1
+  mov.q rdi, 1
+  mov.q rsi, greeting
+  mov.q rdx, greeting_size
+  syscall
+
   mov.d eax, 60
-  mov.d edi, 42
+  mov.d edi, 0
   syscall
 
+greeting:
+  db "Hello, Irenes!", 0x0A
+greeting_size = $ - greeting
+
 file_size = $ - $$