assembly

add 16 bits to 64 bits register [duplicate]

喜夏-厌秋 提交于 2020-01-30 08:38:26
问题 This question already has answers here : Issue storing a byte into a register x86-64 assembly (1 answer) Why can't I move directly a byte to a 64 bit register? (2 answers) Closed 2 years ago . Here is what i want to do: add rsi, word [rsi+16] I want to read the unsigned short value which is at rsi+16 adress. And i want to add this value to rsi. Here is the error i get in nasm: s2.asm:62: error: mismatch in operand sizes This is strange. Why nasm and my cpu are not able to add 16 bits to 64

How to multiply by 2^n in assembly?

拟墨画扇 提交于 2020-01-30 08:08:40
问题 Given 2 numbers, x and n, what's the method to multiply x by 2^n ? For instance x=3.7 and n=5. so 3.7*2^5 = 118.4. I need this done without using the FPU commands (math coprocessor). So i figured that numbers in 32 bt processor are represented by 32 bits: the 1st is for the sign, next 8 (2-9) are for the exponent, and the following 23 are called the SIGNIFICAND. The exponent field is the k in 2^k. So what i need to do is only change the exponent field and add n to it. exponent = exponent + n

How to multiply by 2^n in assembly?

拈花ヽ惹草 提交于 2020-01-30 08:08:25
问题 Given 2 numbers, x and n, what's the method to multiply x by 2^n ? For instance x=3.7 and n=5. so 3.7*2^5 = 118.4. I need this done without using the FPU commands (math coprocessor). So i figured that numbers in 32 bt processor are represented by 32 bits: the 1st is for the sign, next 8 (2-9) are for the exponent, and the following 23 are called the SIGNIFICAND. The exponent field is the k in 2^k. So what i need to do is only change the exponent field and add n to it. exponent = exponent + n

gdb: show corresponding lines in source and asm

百般思念 提交于 2020-01-30 06:52:08
问题 When running gdb in TUI mode, showing source and assembly, is there an option to highlight the set of instructions mapping to a selected source line? 回答1: You can partially do it with GDB Dashboard. https://github.com/cyrus-and/gdb-dashboard From below screenshot you can see that the 1st call to operator<< in this line of code: std::cout << a << std::endl; is mapped to 4 assembly instructions: 0x00000000004011a2 main()+28 mov -0x4(%rbp),%eax 0x00000000004011a5 main()+31 mov %eax,%esi

32b x86 assembly scanf usage

被刻印的时光 ゝ 提交于 2020-01-30 06:34:48
问题 So, I am trying to use the scanf function in 32bit ATT assembly and keep getting segmentation faults, despite using pretty much the same code as the example shown in Computer Systems: A Programmer's Perspective and the assembly generated from my own simple C input program. I have no idea what it is I am doing wrong and would appreciate some help in figuring it out. My test assembly code(which segfaults): .data .align 4 fmt: .string "%d" str: .string "Input a number: " .text .global main .type

32b x86 assembly scanf usage

▼魔方 西西 提交于 2020-01-30 06:34:45
问题 So, I am trying to use the scanf function in 32bit ATT assembly and keep getting segmentation faults, despite using pretty much the same code as the example shown in Computer Systems: A Programmer's Perspective and the assembly generated from my own simple C input program. I have no idea what it is I am doing wrong and would appreciate some help in figuring it out. My test assembly code(which segfaults): .data .align 4 fmt: .string "%d" str: .string "Input a number: " .text .global main .type

Is there a difference between equals sign assignment “x = 1” and “.equ x, 1” or “.set x, 1” in GNU Gas assembly?

让人想犯罪 __ 提交于 2020-01-30 06:08:28
问题 E.g.: a = 1 and: .equ a, 1 and: .set a, 1 all produce the same output byte-by-byte upon: as --32 main.S according to cmp . I know that .equ and .set do the same thing according to the documentation of .equ : https://sourceware.org/binutils/docs-2.25/as/Equ.html : It is synonymous with `.set'. and I know what .equ does from Difference between .equ and .word in ARM Assembly? So what about = ? Is it the same as the other two? 回答1: It is the same. After grepping the documentation source, I've

calling printf from assembly language on 64bit and 32bit architecture using nasm

强颜欢笑 提交于 2020-01-30 04:04:56
问题 I want to call printf function from assembly language in linux. i want to know the method for for 64 bit and 32 bit assembly language programs. 1) please tell me for two cases if i want to pass a 32 bit arguement and 64 bit arguement in printf with a string. how should i do it? 2) for x86 32 bit architecture if i want to do the same thing as in point 1. please tell me the code. and let me know do i need to adjust the stack for both cases and do i just need to pass the arguements in registers?

Printing the x char in a string (MIPS)

我是研究僧i 提交于 2020-01-30 02:37:13
问题 My program is supposed to do the following: -Getting continiously an integer from the user (x), -printing the character at the x position in the string. -The program exits when the user inputs 0. .text .globl __start __start: li $s3,20 #string length start: li $v0,5 syscall move $s0,$a0 #integer now in $a0 beq $s0,$zero,exit li $s1,0 #counter is 0 la $s2,str #address of string now is $s2 loop:lbu $t1,0($s2) #choosing char of string addi $s1,1 #increment counter by 1 addi $s2,1 #next char beq

__do_global_dtors_aux and __do_global_ctors_aux

你说的曾经没有我的故事 提交于 2020-01-29 04:54:24
问题 I disassembled a simple program written in C++ and there are these two function names. I guess that ctor means constructor and dtor means destructor, and word global maybe means that they create and destroy global objects. I cannot guess the name aux. What do these two functions do? 回答1: The addresses of constructors and destructors of static objects are each stored in a different section in ELF executable . for the constructors there is a section called .CTORS and for the destructors there