Dmitry Telenkov 19 hours ago
parent
commit
06f63c7338
8 changed files with 123 additions and 0 deletions
  1. 18 0
      asm/Makefile
  2. 17 0
      asm/test_1.asm
  3. 21 0
      asm/test_2.asm
  4. 21 0
      asm/test_3.asm
  5. 27 0
      asm/test_4.asm
  6. 19 0
      asm/test_5.asm
  7. BIN
      asm/test_5.exe
  8. BIN
      asm/test_5.o

+ 18 - 0
asm/Makefile

@@ -0,0 +1,18 @@
+test_2:
+	as test_2.asm -o test_2.o
+	ld test_2.o -o test_2.exe
+
+test_3:
+	as test_3.asm -o test_3.o
+	ld test_3.o -o test_3.exe
+
+test_4:
+	as test_4.asm -o test_4.o
+	ld test_4.o -o test_4.exe
+
+test_5:
+	as test_5.asm -o test_5.o
+	ld test_5.o -o test_5.exe
+
+clean:
+	rm -rf *.o *.exe

+ 17 - 0
asm/test_1.asm

@@ -0,0 +1,17 @@
+.file "test.asm"
+.data
+
+str: .ascii "test\n"
+.text
+.global _start
+_start:
+
+movq $1, %rax
+movq $1, %rdi
+movq $str, %rsi
+movq $5, %rdx
+syscall
+
+movq $60, %rax
+movq $0, %rdi
+syscall

+ 21 - 0
asm/test_2.asm

@@ -0,0 +1,21 @@
+.file "test_2.asm"
+.data
+str: .ascii "hello world\n"
+
+.text
+.global _start
+
+_start:
+
+    // sys_write
+    movq $1, %rax
+    movq $1, %rdi
+    movq $str, %rsi
+    movq $12, %rdx
+M1:
+    syscall
+M2:  
+    // exit
+    movq $60, %rax
+    movq $0, %rdi
+    syscall

+ 21 - 0
asm/test_3.asm

@@ -0,0 +1,21 @@
+.file "test_3.asm"
+
+.data
+.byte 0x12
+.byte 0x34
+.word 0x1234
+.word 0x56
+.long 0x1234
+.quad 0xabcd
+.word 0x1234
+
+.fill 4, 2, 0xabcd
+.skip 8, 0x12
+.space 16, 0x34
+
+.text
+.global _start
+_start:
+    movq $60, %rax
+    movq $0, %rdi
+    syscall

+ 27 - 0
asm/test_4.asm

@@ -0,0 +1,27 @@
+.file "test_4.asm"
+.data
+data:
+    .byte 0x12
+    .byte 0x32
+    .word 0x5678
+    .space 6, 0x0
+    .text
+
+.global _start
+
+_start:
+
+    //movw $0xabcd, data
+    //movl %eax, 0x402004
+
+    movw date, %ax
+    movq $data, %rbx
+    // или можно сделать так
+    leaq data, %rbx
+
+    // exit
+    movq $60, %rax
+    movq $0, %rdi
+    syscall
+
+

+ 19 - 0
asm/test_5.asm

@@ -0,0 +1,19 @@
+    .file "test_5.asm"
+    .data
+data:
+    .ascii "test\n"
+    .text
+    .global _start
+_start:
+    // print "test\n"
+    movq $1, %rax
+    movq $1, %rdi
+    movb $data, %rsi
+    leaq data, %rsi
+    leaq data(%rip), %rsi // относительная адресация
+    movq %5, %rdx
+
+    // exit
+    movq $60, %rax
+    movq $0, %rdi
+    syscall

BIN
asm/test_5.exe


BIN
asm/test_5.o