nasm

Linux x86-64 Hello World and register usage for parameters

若如初见. 提交于 2020-12-06 04:14:39
问题 I found this page which has a Hello World example for x86-64 on Linux: http://blog.markloiseau.com/2012/05/64-bit-hello-world-in-linux-assembly-nasm/ ; 64-bit "Hello World!" in Linux NASM global _start ; global entry point export for ld section .text _start: ; sys_write(stdout, message, length) mov rax, 1 ; sys_write mov rdi, 1 ; stdout mov rsi, message ; message address mov rdx, length ; message string length syscall ; sys_exit(return_code) mov rax, 60 ; sys_exit mov rdi, 0 ; return 0

Linux x86-64 Hello World and register usage for parameters

落花浮王杯 提交于 2020-12-06 04:14:29
问题 I found this page which has a Hello World example for x86-64 on Linux: http://blog.markloiseau.com/2012/05/64-bit-hello-world-in-linux-assembly-nasm/ ; 64-bit "Hello World!" in Linux NASM global _start ; global entry point export for ld section .text _start: ; sys_write(stdout, message, length) mov rax, 1 ; sys_write mov rdi, 1 ; stdout mov rsi, message ; message address mov rdx, length ; message string length syscall ; sys_exit(return_code) mov rax, 60 ; sys_exit mov rdi, 0 ; return 0

自制操作系统Antz(1)——Boot Sector

孤街浪徒 提交于 2020-12-04 19:08:11
0. 引子    最近在看操作系统底层方面的东西,最开始的为什么是07c00h这个问题就让我对操作系统有了很大的兴趣。所以准备在看书之余顺便写一个操作系统(Anz)。 至于为什么这个系统会被叫做Antz,可以参考Antz Uhl Kone(某个日漫男主的名字), 日语为アインズ·ウール·ゴウン , 与之对应的还有接下来准备写的自制脚本语言AntzScript,因为准备是用Java实现解释器,所以如何把AntzScript运行在Antz上是一个很大问题(其实问题就是引入Java)。   Antz系统更新地址: https://www.cnblogs.com/LexMoon/category/1262287.html   Linux内核源码分析地址: https://www.cnblogs.com/LexMoon/category/1267413.html 1.关于Boot Sector   引导扇区(Boot Sector) 通常指设备的第一个扇区,用于加载并转让处理器控制权给操作系统。    1.1 主引导扇区      硬盘的0柱面、0磁头、1扇区称为 主引导扇区 ,也叫 主引导记录 MBR ,该记录占用512个字节,它用于硬盘启动时将系统控制权转给用户指定的、在分区表中登记了某个 操作系统 分区。MBR的内容是在硬盘分区时由分区软件写入该扇区的,MBR不属于任何一个操作系统

Intel assembly syntax OFFSET

别说谁变了你拦得住时间么 提交于 2020-12-01 10:46:05
问题 Now that i know u can use gcc for Intel syntax instead of default at&t with gcc -S -masm=intel test.c There is this line mov DWORD PTR [ebp-16], OFFSET FLAT:base Is it the same as mov dword[ebp-16], base ? Otherwise what must i do? 回答1: Yes, mov dword [ebp - 16], base should be fine. I haven't seen offset flat: for a while - I think it's obsolete, but it's what AT&T's idea of .intel_syntax used to demand (I had to look at Gas's source code to find that out). Means the same as offset to Masm,

x86汇编入门

社会主义新天地 提交于 2020-11-29 15:30:30
Intel® 64 and IA-32 Architectures Software Developer’s Manual 文档官方地址: https://software.intel.com/sites/default/files/managed/39/c5/325462-sdm-vol-1-2abcd-3abcd.pdf 很好的入门文档:https://www.ibm.com/developerworks/cn/linux/l-assembly/ 汇编语言由三部分组成: 汇编指令:跟机器指令一一对应,实际就算一个个的助记符。有 AT&T 和 INTEL 两种语法 伪指令:给编译器看,用于指示编译器该如何做。不同编译器的语法不同,有 NASM、GNU as 和 MASM 三种常用编译器 运算符:±*/ 之类的符号 汇编指令 具体可以参考:https://blog.csdn.net/kennyrose/article/details/7575952 AT&T 和 INTEL 两种语法的主要差异有: - AT&T INTEL 操作数方向 从左向右 从右向左 立即数表示方式 $0x01 30h 寄存器表示方式 %eax eax 助记符指定操作数长度 b8位,w16位,l32位, movl $lb, %eax mov eax, dw ptr lb 长跳转和调用 ljmp $sect,

Loading a register from a “db 0” doesn't load a 0 into EAX?

旧街凉风 提交于 2020-11-29 10:56:38
问题 I've been bashing my head against the wall for over an hour and I can't understand why the below doesn't work. If I change b: db 1 to b: db 0 then it should print 10, otherwise it should print 0. Instead, the program always prints 10. I've been writing a project that writes assembly and this is one of the unit test that fails and I just don't get it. It has to be something simple. extern printf, exit section .bss section .data b: db 1 x: dd 5 y: dd 5 z: dd 0 int_pattern: db "%i", 10, 0 global

Loading a register from a “db 0” doesn't load a 0 into EAX?

无人久伴 提交于 2020-11-29 10:54:41
问题 I've been bashing my head against the wall for over an hour and I can't understand why the below doesn't work. If I change b: db 1 to b: db 0 then it should print 10, otherwise it should print 0. Instead, the program always prints 10. I've been writing a project that writes assembly and this is one of the unit test that fails and I just don't get it. It has to be something simple. extern printf, exit section .bss section .data b: db 1 x: dd 5 y: dd 5 z: dd 0 int_pattern: db "%i", 10, 0 global

Function that takes a char array and 2 indices; swapping the chars in those indices

邮差的信 提交于 2020-11-29 10:24:54
问题 This is my function prototype: char* swap(char* array, int index1, int index2); This is my assembly code: segment .text global swap swap: mov r14,[rdi+rsi] mov r15,[rdi+rdx] mov [rdi+rsi],r15 ;this line segfaults mov [rdi+rdx],r14 mov rax,rdi ret The lines mov [rdi+rsi],r15 and mov [rdi+rdx],r14 give me a segfault; I'm not sure where I'm going wrong The calling function: #include <stdio.h> #include <stdlib.h> extern char* swapLetters(char* str, int indexA, int indexB); int main() { char* st=