x86

Import constants in x86 with gas

≯℡__Kan透↙ 提交于 2021-01-29 18:25:48
问题 I have the following two files in assembly: # file.s .globl _start _start: mov $10, %edi mov $SYS_EXIT, %eax syscall # utils.s SYS_EXIT = 60 SYS_WRITE = 1 SYS_STDOUT = 1 What is required to be able to link these two files into an executable. To assemble and link I've tried doing: $ as file.s -o file.o $ as utils.s -o utils.o $ ld utils.o file.o -o file # file.o: In function `_start': # (.text+0x8): undefined reference to `SYS_EXIT' Which seems to just mean I'm not properly importing the file

Are these the smallest possible x86 macros for these stack operations?

廉价感情. 提交于 2021-01-29 17:03:41
问题 I'm making a stack based language as a fun personal project. So, I have some signed/unsigned 32-bit values on the stack and my goal is to write some assembly macros that operate on this stack. Ideally these will be small since they'll be used a lot. Since I'm new to x86 assembly I was wondering if you guys had any tips or improvements you could think of. I'd greatly appreciate your time, thanks! Note: An optimizer is used after the macros are expanded to avoid cases like pop eax; push eax so

Can't output coprocessor float from variable two times in a row

谁说胖子不能爱 提交于 2021-01-29 14:35:55
问题 Good afternoon! In this example, I simply add two numbers with a comma, save the variable in tbyte and display the same variable two times in a row on the screen, but the first time I get 11.1 , as it should be, and the second time 4.667261E-062 . Why is this happening? And one more question, is it possible in tbyte to somehow save and access numbers by array type? for example, storing numbers in dd , I just could save and read them in increments of 4, for example, result [0] , result [4] ,

push same value onto stack and ret behaves differently

感情迁移 提交于 2021-01-29 14:31:24
问题 In x-86, if you push a value from a register (for example, %eax), and then return, the program transfers control to the address corresponding to the value at %eax, to my understanding. In another run of the program, if you edited the code so that you pushed onto the stack through a different way (for example, such as dereferencing a register, moving that value to another register, and then pushing this register), and then return, the program should also transfer control to the address

What is the most efficient way to implement a BST in such a way the find(value) function is optimized for random values in the tree on x86? [closed]

梦想的初衷 提交于 2021-01-29 11:39:28
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 1 year ago . Improve this question Suppose we have a binary search tree of depth $n$, where every level is full, we know in advance how big the tree will be, and we will run the find(value) function a lot. The values(integers) we will want to find will be uniformly random across the acceptable

How i can access a variable data using a variable value in adress like [ var_+[second_byte] ]?

社会主义新天地 提交于 2021-01-29 11:00:55
问题 I got this code: BITS 16 data: bytemap: db 0x0, 0x1, 0x4; pixel_x: db 2; to return the 0x4 value main: ; code... mov al, [bytemap+[pixel_x]]; i need that byte in al register ; more code... jmp main; but nasm returns "expression syntax error", i tryed using mov bl, [pixel_x]; mov al, [bytemap+bl] , but don't work, how the right way to do it? ( if it exists )... 回答1: You need to use pointer-width registers in addressing modes . x86 doesn't have memory-indirect addressing modes, only register

Returning to the next instruction following the one stored in Eip register

谁说胖子不能爱 提交于 2021-01-29 09:25:53
问题 I have written a assembly function that handles an interrupt. I want to return to the instruction following the one that caused the interrupt. Here is my code, pushl %ebp movl %esp,%ebp pushal movl %esp, %eax pushl %eax pushl $0 call divzero addl $8, %esp /* add 8 to the stack pointer to skip the two variables*/ popal popl %ebp /* restore %ebp */ popl %eax /* pop return address from stack and store in eax */ add $4, %eax /* add 4 to value of eax to get the address of next instruction */ jmp

Can't add relative quantities, assembly error

假如想象 提交于 2021-01-29 09:20:28
问题 so for a project i need to program a game in 80386 (32-bit processor). To draw a pixel we got this example code from the teacher: -first set the video mode: MOV ah, 00h MOV al, 13h INT 10h -drawing the pixel: MOV ESI, 0A0000H ; frame buffer address MOV EDI, 320 * 2 + 10; add the appropriate offset MOV AL, 10 ; index in the colour palette MOV [EDI], AL ; change pixel at column 10 of row 2 This code works perfectly, but in my game code i want to add in the data the x and y positions of the

How to do a reverse offset/index in x86 [duplicate]

这一生的挚爱 提交于 2021-01-29 06:12:09
问题 This question already has answers here : Can't subtract registers in an addressing mode? (3 answers) Subtracting registers with an LEA instruction? (1 answer) Referencing the contents of a memory location. (x86 addressing modes) (2 answers) Printing an integer as a string with AT&T syntax, with Linux system calls instead of printf (2 answers) Closed 4 months ago . I am trying to do a negative offset for memory addressing. This is to convert a number to a string and make sure that it doesn't

How are segment registers involved in memory address translation?

孤街醉人 提交于 2021-01-29 05:29:58
问题 In what I've learned so far about segmentation: A virtual address contains a segment selector and an offset The segment selector is used in conjunction with the GDTR to find the linear address of the segment descriptor The segment descriptor houses information regarding the chosen segment, including its linear address So, my questions are: Based on what I've read, the virtual address is loaded into the segment register, and then somehow the translation is continued from there. What happens to