nasm

NASM Segmentation fault when modifying a variable that should be in the read-write .data section (section .data doesn't work without a space?)

余生长醉 提交于 2021-02-15 07:40:23
问题 I'm having an issue with a program I'm writing in NASM using SASM, I'm using a variable as a counter and once I modified it and try to to save the new value at the used address in memory I get a segmentation fault. Here are the bits of code concerning the variable: section.data p_count DW 0 section.text global CMAIN CMAIN: mov ebp, esp; for correct debugging mov bx, [p_count] inc bx mov [p_count], bx ret The program stops running when it arrives at the last line here. Anyone has an idea what

《操作系统真象还原》MBR

邮差的信 提交于 2021-02-12 05:21:53
  以下是读本书第三章的收获。   如何知道一个源程序的各符号(指令和变量)地址?简单来说,地址就是该符号偏移文件开头的距离,符号的地址是按顺序编排的,所以两个相邻的符号,其地址也是相邻的。对于指令来说,指令的地址=上一个指令的地址+上一个指令的大小,最初的符号地址为0,可以根据此公式推算出所有符号的地址。 section称为节,它是提供给程序员编排程序用的,我们可以将一段读取字符串的代码放在section A下,将读取硬盘的代码放进section B下,可以给A,B换成一个更具体的名字,来提高可读性。 例如,下图这段代码,将整个程序分成section code和section data两节,顾名思义,就是存放代码和数据的两个section,这样我们就很清楚地知道每部分代码是做什么用的。另一个值得注意的细节是section并不会对符号的编址用什么影响,去掉section和不去掉其实符号的地址都是一样的。 vstart用于告诉编译器,之后的符号都以某个地址为初始地址来编址。如下图,像$$的地址替换成以0x7c00为初始地址的地址,符号var1和var2的地址被替换成以0x900的地址。 当然,我们还可以通过section.节名称.start来获得在文件中真正的地址。如section.code.start值为0x0,即section code偏移文件的距离为0

《操作系统真象还原》BIOS

拜拜、爱过 提交于 2021-02-12 04:56:49
  以下是读本书第二章的收获。   记得我大学学习操作系统的时候会遇到一些奇奇怪怪的问题,因为觉得问题太奇怪了,所以羞于问老师。诸如 ROM到底是个什么东西 ;如果用 内存映射的方式访问外部设备,是不是内存条里专门有块内存空间来用于访问供外部设备 ,是不是先访问内存条这个地址,然后就直接跳到访问这个设备了等等。幸运的是,这本书都给我一一解答了。   实际上,ROM是下图这样的一种只读存储器(取自百度百科),是一种即使没有通电,也能保存信息的存储器。ROM其实是既可以读也可以写,只不过由于历史原因统称只读存储器。ROM种类不少,我们常用的固态硬盘就是基于闪存(一种ROM)的存储器。   我们下面将要说的BIOS正是存储在ROM设备中的程序,为什么BIOS放在ROM上?个人觉得,BIOS每次通电开机时都要运行,所以是不适合RAM这种断电即丢失信息的存储器了;至于磁盘也不太适合了,我们知道CPU能够直接访问的只有寄存器和内存,不包括磁盘这种外围设备。所以要执行在磁盘中程序的话,首先要将代码加载到内存里,再让CPU从内存取指令出来执行,但因为此时还未执行BIOS程序,换句话说,我们还没有对硬件IO操作的功能,所以将代码从磁盘里加载出来的功能还不能使用。这样的话,磁盘程序放不出BIOS,BIOS也执行不了初始化操作,将BIOS放在硬盘估计就是让BIOS和硬盘俩对着对方干瞪眼,所以硬盘并不适合

CMake: Howto test for compiler, before enable a language

一曲冷凌霜 提交于 2021-02-11 17:20:06
问题 In my project some code can be optional compiled in a different language (nasm & fortran), but it's also fine to compile the project without having these compiler installed. E.g. on Windows. I would like to check if the the compiler are installed, before enabling the languages with enable_language enable_language(ASM_NASM) enable_language(Fortran) If I use enable_language without an additional check, CMake stops with an error message. (At the moment I check for if (MSVC) as workaround.) Btw.

Linux sys_open in 64-bit NASM returns negative value

耗尽温柔 提交于 2021-02-11 08:52:29
问题 I am opening an existing file to write into it, using sys_open and sys_write. The sys_write works correctly when I create a new file as shown below. But if I use sys_open, the return value is negative (-13, which is "Permission denied") and the write doesn't work (of course). This works: section .data File_Name: db '/opt/Test_Output_Files/Linux_File_Test',0 File_Mode: dq 754q Write_Buffer: db 'This is what I want to write',0 section .text ; Create file mov rax,85 ; sys_creat mov rdi,File_Name

label inconsitently redefined NASM

我的梦境 提交于 2021-02-10 17:47:32
问题 i have been following a YouTube tutorial on how to make an operating system, as well as experimenting with writing assembly code my self. I use NASM to turn my assembly files into executable binaries, and use qemu to run them. -=-=-=-=-= boot.asm [org 0x7c00] mov [BOOT_DISK], dl mov bp, 0x7c00 mov sp, bp mov bx, tst call pst call readisk %include 'print.asm' %include 'diskread.asm' jmp $ times 510-($-$$) db 0 db 0x55, 0xaa -=-=-=-=-= diskread.asm PROGRAM_SPAVE equ 0x7e00 readisk: mov bx,

label inconsitently redefined NASM

别来无恙 提交于 2021-02-10 17:46:35
问题 i have been following a YouTube tutorial on how to make an operating system, as well as experimenting with writing assembly code my self. I use NASM to turn my assembly files into executable binaries, and use qemu to run them. -=-=-=-=-= boot.asm [org 0x7c00] mov [BOOT_DISK], dl mov bp, 0x7c00 mov sp, bp mov bx, tst call pst call readisk %include 'print.asm' %include 'diskread.asm' jmp $ times 510-($-$$) db 0 db 0x55, 0xaa -=-=-=-=-= diskread.asm PROGRAM_SPAVE equ 0x7e00 readisk: mov bx,

Nasm print to next line

限于喜欢 提交于 2021-02-10 07:14:27
问题 I have the following program written in nasm Assembly: section .text global _start: _start: ; Input variables mov edx, inLen mov ecx, inMsg mov ebx, 1 mov eax, 4 int 0x80 mov edx, 2 mov ecx, num1 mov ebx, 0 mov eax, 3 int 0x80 mov edx, inLen mov ecx, inMsg mov ebx, 1 mov eax, 4 int 0x80 mov edx, 2 mov ecx, num2 mov ebx, 0 mov eax, 3 int 0x80 ; Put input values in correct registers mov eax, [num1] sub eax, '0' ; convert char to num mov ebx, [num2] sub ebx, '0' ; convert char to num ; Perform

Nasm print to next line

早过忘川 提交于 2021-02-10 07:12:03
问题 I have the following program written in nasm Assembly: section .text global _start: _start: ; Input variables mov edx, inLen mov ecx, inMsg mov ebx, 1 mov eax, 4 int 0x80 mov edx, 2 mov ecx, num1 mov ebx, 0 mov eax, 3 int 0x80 mov edx, inLen mov ecx, inMsg mov ebx, 1 mov eax, 4 int 0x80 mov edx, 2 mov ecx, num2 mov ebx, 0 mov eax, 3 int 0x80 ; Put input values in correct registers mov eax, [num1] sub eax, '0' ; convert char to num mov ebx, [num2] sub ebx, '0' ; convert char to num ; Perform

Nasm print to next line

六眼飞鱼酱① 提交于 2021-02-10 07:11:36
问题 I have the following program written in nasm Assembly: section .text global _start: _start: ; Input variables mov edx, inLen mov ecx, inMsg mov ebx, 1 mov eax, 4 int 0x80 mov edx, 2 mov ecx, num1 mov ebx, 0 mov eax, 3 int 0x80 mov edx, inLen mov ecx, inMsg mov ebx, 1 mov eax, 4 int 0x80 mov edx, 2 mov ecx, num2 mov ebx, 0 mov eax, 3 int 0x80 ; Put input values in correct registers mov eax, [num1] sub eax, '0' ; convert char to num mov ebx, [num2] sub ebx, '0' ; convert char to num ; Perform