nasm

how to accept input from command line in a assembly program build using gcc tools?

我们两清 提交于 2020-01-06 14:02:10
问题 I actually wanted to write a program in assembly(linux) , to accept filename from the command line and I was successful by retrieving the values from the stack using successive pop opcodes when I used "ld" command to build but I was unsuccessful when i used "gcc" command . I need to use gcc because I will be using various C std library function in this program. Actually the file was creating , but its always got a "Invalid encoding " label and appeared like <? G ? in the directory.I wanted to

Difference in data alignment in struct vs parameter?

余生颓废 提交于 2020-01-06 13:09:12
问题 Given the following code: typedef struct tagRECT { int left; int top; int right; int bottom; } RECT; extern int Func(RECT *a, int b, char *c, int d, char e, long f, int g, int h, int i, int j); int main() { } void gui() { RECT x = {4, 5, 6, 7}; Func(&x, 1, 0, 3, 4, 5, 6, 7, 8, 9); } This is the assembly generated gcc x86_64 presumably on linux (I used compiler explorer). main: mov eax, 0 ret gui: push rbp mov rbp, rsp sub rsp, 16 ; RECT x assignment mov DWORD PTR [rbp-16], 4 mov DWORD PTR

Assembly: [SI + CX] = impossible combination of address sizes

北战南征 提交于 2020-01-06 12:44:14
问题 So, today I tried to create a library for my in-development OS with one simple function: To print characters on screen. To use this function I simply have to push the string address to the stack and call it (The string must end with a 0x00 byte). Below is the source code of the function: __print: ;Print string that is terminated with a 0x00 to screen __print_prepare: pop si ;SI Register = String Address mov ah, 0x0E ;0x0E Function = Print Character on screen mov bx, 0x0F ;Background = Black,

Assembly: [SI + CX] = impossible combination of address sizes

巧了我就是萌 提交于 2020-01-06 12:43:11
问题 So, today I tried to create a library for my in-development OS with one simple function: To print characters on screen. To use this function I simply have to push the string address to the stack and call it (The string must end with a 0x00 byte). Below is the source code of the function: __print: ;Print string that is terminated with a 0x00 to screen __print_prepare: pop si ;SI Register = String Address mov ah, 0x0E ;0x0E Function = Print Character on screen mov bx, 0x0F ;Background = Black,

writing to a file in nasm using system calls

时光毁灭记忆、已成空白 提交于 2020-01-06 08:36:09
问题 As part of an assignment I'm supposed to write to a file using system calls. Everything works fine except when I try to open the file in gedit (linux), it says it can't identify the character encoding. Notepad (on windows) opens the file just fine. Why doesn't it work on linux ? here's the code: section .text global _start _start: mov EAX, 8 mov EBX, filename mov ECX, 0700 int 0x80 mov EBX, EAX mov EAX, 4 mov ECX, text mov EDX, textlen int 0x80 mov EAX, 6 int 0x80 mov eax, 1 int 0x80 section

Multi-Digit Input from NASM

可紊 提交于 2020-01-06 08:17:15
问题 So I'm fairly new to Assembly language I have a pretty solid grasp on the fundamentals but user input has always baffled me. So right now I have the following code to receive a single digit from the user: mov eax, 3 mov ebx, 0 mov ecx, inStrBuf mov edx, StrLen int 80h And then the definitions are as follows SECTION .bss inStrBuf: times StrLen resb ' ' Section .data StrLen: equ 8 After I put the value in ecx, the value is the digit + 2608. So what I have been doing is simply subtracting 2608

Passing arrays to NASM DLL, pointer value gets reset to zero

孤街醉人 提交于 2020-01-06 05:16:11
问题 I am passing three arrays of doubles from Python (3.6.2) into a DLL written in 64-bit NASM (Windows) using CTypes. The pointers to the arrays are in rcx, rdx, r8 and r9. On entry, I extract the pointers into three separate arrays, called a_in_data, b_in_data, and c_in_data. The elements of those arrays are (1) pointer (2) data type and (3) length. In the area preceded by "Test #1" in the code below we check the value at b_in_data[0] and we get a valid pointer (just remove the comment symbols

nasm and gcc: 32 bit linking failed (64 bit Mac OS X)

被刻印的时光 ゝ 提交于 2020-01-06 03:03:09
问题 I've just compiled a assembley file with nasm this way: $ nasm -f elf somefile.asm -o somefile.o After that I want to link somefile.o to a programm with gcc $ gcc -m32 somefile.o -o someprogramm But linking the file prints the following error: ld: warning: ignoring file somefile.o, file was built for unsupported file format which is not the architecture being linked (i386) Undefined symbols for architecture i386: "_main", referenced from: start in crt1.10.6.o ld: symbol(s) not found for

Compare and jump instruction as one instruction

╄→гoц情女王★ 提交于 2020-01-06 03:02:06
问题 Is there a way I can compare and jump in one instruction: C code: 1. while(i<10) 2. {i++} Assembly code: (eax=0)(ecx=10) .while: cmp eax, ecx jge .endofwhile add eax, 1 jmp .while .endofwhile: Is there a way i can do line 2 and 3 in one instruction? 回答1: Yes, you can have the test and branch treated as a single instruction, and the way to do this is to write them as two instructions like you did, to use a modern Intel processor and to follow a few simple rules (the branch instruction must be

Error addressing memory when using`esp*scale

喜你入骨 提交于 2020-01-05 06:42:48
问题 The memory addressing general form (found it here) is: [base + index*scale + disp] When I try to assemble/compile the following code: mov eax, [ebx + esp*4 + 2] NASM gives the following error: "error: invalid effective address" . But the following works fine: mov eax, [ebx + esp + 2] And the following works fine also: mov eax, [ebx + ecx*4 + 2] So it looks like using a scale with esp as the index register causes the error. Am I correct? and where can I read more about this (other than the