当在汇编器中进行系统调用sys_read(int80h,eax中的值为3)时,调用后寄存器eax中将存储什么?是读取的字符串中的字符数吗?
我想知道是否可以在另一个 C 文件中访问类似的汇编指令.directive或类似的宏%macro my_macro
文件:macroasm.S
%macro my_macro 1
mov rsp, 1
%endmacro
Run Code Online (Sandbox Code Playgroud)
有没有可能的方法来调用和执行my_macroC 文件中的宏并使用 nasm 和 gcc 编译它们?
首先,我是汇编新手,但在 C++ 方面有不错的背景。我的问题源于我使用 assembly关注命令行参数的教程。
当程序运行时,它会根据教程执行它应该做的一切,即显示程序输入列表:
./asm1 arg1 arg2 arg3
问题是当您提供星号作为参数时:
./asm1 *
它有效地在 CWD 上执行/usr/bin/ls。
我的问题是如何防止这种情况发生,以及有关实施该计划的更好方法的任何建议。
替换:
; the loop
cmp ecx, eax ; if ecx not equal to eax
jne begin_for_loop ; jmp to loop, else exit
Run Code Online (Sandbox Code Playgroud)
和:
; the loop
cmp ecx, eax ; if ecx not equal to eax
jmp begin_for_loop ; jmp to loop, else exit
Run Code Online (Sandbox Code Playgroud)
我发现了一个更大的问题,即程序将 ENV 变量打印到屏幕上。
; FOR LOOP: Print commandline arguments> an equivalent program to …Run Code Online (Sandbox Code Playgroud) 我正在编写一个简单的 NASM 汇编引导扇区。该代码应在 16 位实模式下将文本打印到屏幕上,然后切换到 32 位保护模式并将文本打印到屏幕上。
我使用 QEMU 作为我的 CPU 模拟器,它按照应有的方式从 16 位模式打印文本。但是,在 32 位模式下应该打印的文本不会打印。
我认为这是我的代码的问题,但我也运行了类似的代码,同样的问题是仅在 16 位模式下工作。
是我没有正确使用 QEMU,还是我弄乱了其他东西?我的代码是:
引导扇区.asm
; Boot sector that enters 32 bit protected mode
[org 0x7c00]
mov bp, 0x9000 ; Set stack
mov sp, bp
mov bx, MSG_REAL_MODE
call print_string
call switch_to_pm ; We will never return to here
jmp $
%include "print_string.asm"
%include "gdt.asm"
%include "print_string_pm.asm"
%include "switch_to_pm.asm"
[bits 32]
;Where we arrive after switching to PM
BEGIN_PM:
mov ebx, …Run Code Online (Sandbox Code Playgroud) 我正在遵循这个例子。但我收到了这个错误。有人知道如何解决这个问题吗?我正在 Mac OS X 10.14.1 上运行。
$ nasm -o hello_world.o hello_world.asm
hello_world.asm:8: error: instruction not supported in 16-bit mode
hello_world.asm:9: error: instruction not supported in 16-bit mode
hello_world.asm:10: error: instruction not supported in 16-bit mode
hello_world.asm:11: error: instruction not supported in 16-bit mode
hello_world.asm:15: error: instruction not supported in 16-bit mode
hello_world.asm:16: error: instruction not supported in 16-bit mode
$ nasm --version
NASM version 2.13.03 compiled on Feb 8 2018
Run Code Online (Sandbox Code Playgroud)
section .data
hello_world db "Hello world!", 10
section …Run Code Online (Sandbox Code Playgroud) 当我有这样的操作时mov eax, [input+10]:
它是否具有与此操作不同的操作码:
mov eax, [input](考虑到输入现在具有前值input+10)?
我知道这int 0x80会在 linux 中造成中断。但是,我不明白这段代码是如何工作的。它会返回一些东西吗?
代表什么$ - msg?
global _start
section .data
msg db "Hello, world!", 0x0a
len equ $ - msg
section .text
_start:
mov eax, 4
mov ebx, 1
mov ecx, msg
mov edx, len
int 0x80 ;What is this?
mov eax, 1
mov ebx, 0
int 0x80 ;and what is this?
Run Code Online (Sandbox Code Playgroud) 我想知道在 NASM 中使用“resb”时保留哪种类型的存储。我很确定它是 RAM,但我想确定(也许是 CPU 缓存?)。我在研究中所能找到的只是它保留在 .bss 部分,但这并不能回答我的问题。任何帮助表示赞赏。谢谢。
在 NASM 环境中运行以下 MASM 命令时出现错误:
MOV BYTE PTR [DI-02H],0FH
Run Code Online (Sandbox Code Playgroud)
它给出了一个错误和一个警告消息:
warning: 'PTR' is not a NASM keyword [-w+ptr]
error: symbol 'PTR' not defined
Run Code Online (Sandbox Code Playgroud)
在这里我想知道 MASM 的“PTR”的 NASM 选项是什么。
我试图在实模式下绘制到屏幕,所以我试图使用分段访问 0xB8000
我的汇编代码是这样的
[BITS 16]
org 0x7c00
begin:
mov ah, 0x01 ; disable cursor
mov ch, 0x3f
int 0x10
mov ch, 0x0000
mov cs, 0xb800
mov ah, 0x0000
mov [cs:ah], ch ; invalid effective address
end:
jmp end
times 510 - ($-$$) db 0
dw 0xaa55
Run Code Online (Sandbox Code Playgroud)
我将如何正确使用分段来解决 0xB8000?