我看到代码如下:
mov ax, cs
mov ds, ax
mov es, ax
Run Code Online (Sandbox Code Playgroud)
为什么我不能将其压缩为:
mov ds, cs
mov es, cs
Run Code Online (Sandbox Code Playgroud)
自使用累加器寄存器以来,第一种方式更快吗?但这似乎并不直观,因为cs和ds是段寄存器.还是有一些我不知道的限制?
顺便说一句,我正在使用nasm.
我正在尝试使用当前系统时间为随机数生成器播种.如何使用NASM访问系统时间?(我正在使用linux)
我决定创建一个使用Linux系统调用的简单猜测数字游戏,以及一些C函数来提供更简单的界面.当我将int转换为字符串并在屏幕上打印正确答案时,我似乎遇到了分段错误.
这是输出:
Enter A Number One Through Ten:" :
3
Response did not match! The Answer Is:Segmentation fault
Run Code Online (Sandbox Code Playgroud)
这是C代码:
// print.c
#include "/usr/include/stdio.h"
#include "/usr/include/string.h"
#include "/usr/include/stdlib.h"
#include "/usr/include/time.h"
void print(const char* msg)
{
printf(msg);
return;
}
int compare(const char* str, const char* str2)
{
int i = strcmp(str, str2);
if (i == 0)
{
return 1;
}
else
{
return 0;
}
}
int divide(int num, int dem)
{
if (dem == 0)
{
printf("Undefined");
return 0;
}
else …Run Code Online (Sandbox Code Playgroud) 首先,这是家庭作业.
我正在尝试将5位数字读入寄存器bx.假设该数字不大于65535(16位).以下是我试图这样做的方式.
但是,当我尝试打印数字时,我只打印输入的最后一个数字.这让我想到,当我向bx添加另一个号码时,它会覆盖以前的号码,但我无法看到问题.任何帮助将不胜感激,我几乎可以肯定它是一个小我忽略的东西: - /
mov cx,0x05 ; loop 5 times
mov bx,0 ; clear the register we are going to store our result in
mov dx,10 ; set our divisor to 10
read:
mov ah,0x01 ; read a character function
int 0x21 ; store the character in al
sub al,0x30 ; convert ascii number to its decimal equivalent
and ax,0x000F ; set higher bits of ax to 0, so we are left with the decimal
push ax ; store …Run Code Online (Sandbox Code Playgroud) 我正在创建自己的"玩具"操作系统,我已经到了我试图理解链接和可执行格式的地步 - 特别是我有一个平面文件二进制格式可执行文件,我将其加载到内存中的地址0x500然后直接打电话.作为一个例子考虑以下两个指令(我知道它的设计,我只想在我的样本中包括a call和mov)
mov ax, some_label
call some_label
; some_label is at address 0x99 into the resulting binary
Run Code Online (Sandbox Code Playgroud)
到目前为止,我一直使用NASM通过org 0x500命令使用指令来产生所需的输出nasm -f bin myfile.asm.生成的反汇编看起来像这样并且完美地运行:
mov ax, 0x599
call 0x599
Run Code Online (Sandbox Code Playgroud)
我现在想开始使用LD,以便我可以链接其他对象,但经过大量的实验和阅读后,我仍然不明白为什么能够获得可靠的结果.
我收集的比为了产生类似的输出我需要:
.textsection 的地址相关联0x500,然后将结果作为平面二进制文件发出 - 链接器最终决定在最终二进制文件中解析各种偏移量.到目前为止,我已经尝试了以下内容:
:: Output as ELF
nasm -f elf myfile.asm
:: Then link and output as binary with the address of .text as 0x500
ld --oformat binary -Ttext 0x500 myfile.o
Run Code Online (Sandbox Code Playgroud)
但是这给了我以下错误(这是在Mingw上):
ld:不能对非PE输出文件进行PE操作 …
我想查看特定代码片段的汇编输出,通常我更喜欢阅读nasm语法与AT&T语法相比.有没有一种方便的方法从gcc获取nasm汇编格式输出?
我有一个文件定义了非常基本的IO函数,我想创建另一个使用该文件的文件.
有没有办法将这两个文件联系起来?
prints.asm:
os_return:
;some code to return to os
print_AnInt:
;some code to output an int, including negatives - gets param from stack
print_AChar:
;some code to output a char - gets param from stack
Run Code Online (Sandbox Code Playgroud)
usingPrintTest.asm:
main:
push qword 'a'
call print_AChar ;gets this from prints.asm somehow (that's my question)
call os_return ;and this too..
Run Code Online (Sandbox Code Playgroud)
注意这些不是实际的文件......它们只是用于解释我的问题:)
谢谢!
我正在阅读英特尔处理器文档并同时编写一些基本的汇编代码.我在我的服务器上有两个nasm和as(GAS),我理解两个汇编程序的基本区别.
长期来说:
我也很感激您可以与我分享的任何偏好.
我正在尝试在linux上学习基础知识,我找不到一个很好的参考.NASM文档似乎假设您已经知道masm ...我在cmp(英特尔指令参考之外)的文档中找不到任何示例.
我编写了一个从stdin读取单个字节并将其写入stdout的程序.下面是我的修改,尝试在stdin上检测EOF并在达到EOF时退出.问题是它永远不会退出.我只是继续打印从stdin读取的最后一个char.问题是在我的EOF检测(cmp ecx, EOF)和/或我跳到_exit标签(je _exit)我认为.
我究竟做错了什么?
%define EOF -1
section .bss
char: resb 1
section .text
global _start
_exit:
mov eax, 1 ; exit
mov ebx, 0 ; exit status
int 80h
_start:
mov eax, 3 ; sys_read
mov ebx, 0 ; stdin
mov ecx, char ; buffer
cmp ecx, EOF ; EOF?
je _exit
mov edx, 1 ; read byte count
int 80h
mov eax, 4 ; sys_write
mov ebx, …Run Code Online (Sandbox Code Playgroud) 开始自学组装(NASM)我想知道如何划分2个数字(例如在Windows上).
我的代码看起来像这样,但它崩溃了.
global _main
extern _printf
section .text
_main:
mov eax, 250
mov ebx, 25
div ebx
push ebx
push message
call _printf
add esp , 8
ret
message db "Value is = %d", 10 , 0
Run Code Online (Sandbox Code Playgroud)
我想知道什么是真的错了?它甚至不显示除法后的值.