nasm

Can't link a shared library from an x86-64 object from assembly because of PIC

女生的网名这么多〃 提交于 2020-03-14 14:50:35
问题 I'm porting a shared library from 32-bit to 64-bit. It's composed of some assembly (written for NASM) that exports several procedures and a little bit of higher-level C glue code. I'm building on a 64-bit Debian machine with NASM 2.10.01 and GNU ld 2.22. Having fixed all the push/pop issues (pushing 32-bit parts of registers obviously won't work in 64-bit mode), I've got the object to assemble, but now I'm halted by the linking stage. Here are my command lines - assembly: nasm -Ox -dPTC_ARCH

Can't link a shared library from an x86-64 object from assembly because of PIC

依然范特西╮ 提交于 2020-03-14 14:47:27
问题 I'm porting a shared library from 32-bit to 64-bit. It's composed of some assembly (written for NASM) that exports several procedures and a little bit of higher-level C glue code. I'm building on a 64-bit Debian machine with NASM 2.10.01 and GNU ld 2.22. Having fixed all the push/pop issues (pushing 32-bit parts of registers obviously won't work in 64-bit mode), I've got the object to assemble, but now I'm halted by the linking stage. Here are my command lines - assembly: nasm -Ox -dPTC_ARCH

Can't link a shared library from an x86-64 object from assembly because of PIC

六眼飞鱼酱① 提交于 2020-03-14 14:45:05
问题 I'm porting a shared library from 32-bit to 64-bit. It's composed of some assembly (written for NASM) that exports several procedures and a little bit of higher-level C glue code. I'm building on a 64-bit Debian machine with NASM 2.10.01 and GNU ld 2.22. Having fixed all the push/pop issues (pushing 32-bit parts of registers obviously won't work in 64-bit mode), I've got the object to assemble, but now I'm halted by the linking stage. Here are my command lines - assembly: nasm -Ox -dPTC_ARCH

Garbage in string output function

China☆狼群 提交于 2020-03-04 08:31:09
问题 I'm trying to write a printf replacement in asm and so far have this code: ; string is loaded into r8 print_string: push rax push rbx push rsi push rdx ; load string pointer into ecx mov rsi, r8 ; loop over every char print_string_loop0: cmp sil, 0 ; stop when encounter null character je print_string_return mov rax, 1 ; syscall (sys_write) mov rdi, 1 ; file descriptor for write (stdout = 1) mov rdx, 1 ; bytes to write (1 character) syscall inc rsi jmp print_string_loop0: print_string_return:

Garbage in string output function

半世苍凉 提交于 2020-03-04 08:30:30
问题 I'm trying to write a printf replacement in asm and so far have this code: ; string is loaded into r8 print_string: push rax push rbx push rsi push rdx ; load string pointer into ecx mov rsi, r8 ; loop over every char print_string_loop0: cmp sil, 0 ; stop when encounter null character je print_string_return mov rax, 1 ; syscall (sys_write) mov rdi, 1 ; file descriptor for write (stdout = 1) mov rdx, 1 ; bytes to write (1 character) syscall inc rsi jmp print_string_loop0: print_string_return:

NASM汇编语言基础

眉间皱痕 提交于 2020-02-26 06:09:08
NASM(NetWide Assembler)是可移植性高的80x86汇编器,支持多种目标文件格式。 源代码行格式 [标号] [指令] [注释] 标号由字母、数字、下划线、点号、问号、~、$、@、#组成,必须以字母、下划线、点号或问号开始,区分字母大小写,后缀冒号可选。标号所辖区域从当前开始直到另一标号开始,以点号开始的标号称局部标号,属于当前非局部标号,可用所属标号限定。 指令包括计算机支持的机器指令和NASM支持的伪指令,通常由操作码和操作数组成,多个操作数之间用逗号分隔。 注释以分号开始,直到行尾。 伪指令 1、 定义数据(初始化) DB|DW|DD|DQ|DT <数据> ;DQ、DT只允许小数,DD可以是小数。 2、 保留空间(未初始化) RESB|RESW|RESD|RESQ|REST <数量> 3、包含二进制文件(插入数据) INCBIN “文件名”[,<跳过字节数>[,最多插入字节数]] 4、定义符号常量 <符号名> EQU <数字> ;定义后不可修改 5、重复汇编 TIMES <次数> <指令> ;将指令重复n次 表达式 表达式主要用来形成操作数,在汇编时计算。其中$和$$分别表示当前汇编地址与汇编起始地址。 1、 常量 A、 整数:二进制(前缀B)、八进制(前缀Q)、十进制、十六进制(前缀0X或$以及后缀H)。 B、 小数:数字.[数字][[E|e][+|-]数字

Reproduce these C types in assembly?

依然范特西╮ 提交于 2020-02-08 09:58:33
问题 I am trying to reproduce two opaque data types from the pthreads library in NASM. These data types are pthread_attr_t and cpu_set_t from pthread_attr_setaffinity_np (see http://man7.org/linux/man-pages/man3/pthread_attr_setaffinity_np.3.html). I created a simple C program to call pthread_attr_setaffinity_np and stepped through it with gdb to examine the format of those two bitmasks (pthread_attr_t is an affinity mask). When I debug the C version with gdb, I print the values of attr and cpus:

How to add numbers and display them to the console in a bootloader?

删除回忆录丶 提交于 2020-02-05 15:49:28
问题 I'm creating bootloader that should plus 512 to variable and print result until reaching the specified number. For me, it is 4194304, but the problem is that I really don't understand how to plus these numbers, because at the end I always get nothing or corrupted string. So how should I plus numbers correct? cpu 386 bits 16 org 0h start: cld xor ax,ax mov ss,ax mov sp,7c00h ; setup stack mov ax,8000h mov es,ax ; initialize es w/ 8000h mov ds,ax ; initialize ds w/ 8000h ;======================

why is segmention fault while printing?

我的梦境 提交于 2020-01-30 12:21:26
问题 This is my x86 assembly code: section .data output db '%d',10,0 section .text global main extern printf main : xor ecx,ecx xor eax,eax mov eax,1 mov ecx,5 lable1: push ecx push eax cmp eax,0 jg print pop eax pop ecx inc eax loop lable1 ret print: push eax push output call printf add esp,8 ret This program should print all numbers between 1 to 5. Why am I getting a segmentation fault after printing '1'? 回答1: print ends with a ret instruction, which implies that it is something that you should

Link assembly NASM code to GCC

为君一笑 提交于 2020-01-30 09:05:43
问题 I have a trouble with a compiling assembly code (nasm). On Linux (elf32) it not fails after compilation using g++, but when I tried to build it with i686-w64-mingw32-g++ (for Win32) it failed. My build.sh script: #!/bin/bash nasm -fwin32 wct.asm i686-w64-mingw32-g++ -m32 -O2 -Wall -fno-exceptions -ffloat-store -ffast-math -fno-rounding-math -fno-signaling-nans -fcx-limited-range -fno-math-errno -funsafe-math-optimizations -fassociative-math -freciprocal-math -ffinite-math-only -fno-signed