assembly

Why am I allowed to exit main using ret?

白昼怎懂夜的黑 提交于 2021-02-10 05:10:46
问题 I am about to figure out how exactly a programm stack is set up. I have learned that calling the function with call pointer; Is effectively the same as: mov register, pc ;programcounter add register, 1 ; where 1 is one instruction not 1 byte ... push register jump pointer However, this would mean that when the Unix Kernel calls the main function that the stack base should point to reentry in the kernel function which calls main. Therefore jumping "*rbp-1" in the C - Code should reenter the

Why am I allowed to exit main using ret?

独自空忆成欢 提交于 2021-02-10 05:07:11
问题 I am about to figure out how exactly a programm stack is set up. I have learned that calling the function with call pointer; Is effectively the same as: mov register, pc ;programcounter add register, 1 ; where 1 is one instruction not 1 byte ... push register jump pointer However, this would mean that when the Unix Kernel calls the main function that the stack base should point to reentry in the kernel function which calls main. Therefore jumping "*rbp-1" in the C - Code should reenter the

How can I link dynamically to glibc in Ubuntu

十年热恋 提交于 2021-02-10 05:02:36
问题 I am trying to assemble and link this tiny x86 assembly code in Linux (Ubuntu 18.04 LTS): ;hello.asm global _start extern scanf, printf, exit section .data read_name db '%255s', 0 msg db 'Hello, %s', 0 section .text _start: sub esp, 256 push esp push read_name call scanf add esp, 8 push esp push msg call printf add esp, 264 push dword 0 call exit I am using nasm to assemble and ld to link. As you can probably tell, the code uses C functions, so it has to be linked to glibc . Since my code is

How can I link dynamically to glibc in Ubuntu

百般思念 提交于 2021-02-10 05:00:33
问题 I am trying to assemble and link this tiny x86 assembly code in Linux (Ubuntu 18.04 LTS): ;hello.asm global _start extern scanf, printf, exit section .data read_name db '%255s', 0 msg db 'Hello, %s', 0 section .text _start: sub esp, 256 push esp push read_name call scanf add esp, 8 push esp push msg call printf add esp, 264 push dword 0 call exit I am using nasm to assemble and ld to link. As you can probably tell, the code uses C functions, so it has to be linked to glibc . Since my code is

How can I link dynamically to glibc in Ubuntu

不羁岁月 提交于 2021-02-10 05:00:10
问题 I am trying to assemble and link this tiny x86 assembly code in Linux (Ubuntu 18.04 LTS): ;hello.asm global _start extern scanf, printf, exit section .data read_name db '%255s', 0 msg db 'Hello, %s', 0 section .text _start: sub esp, 256 push esp push read_name call scanf add esp, 8 push esp push msg call printf add esp, 264 push dword 0 call exit I am using nasm to assemble and ld to link. As you can probably tell, the code uses C functions, so it has to be linked to glibc . Since my code is

How can I link dynamically to glibc in Ubuntu

百般思念 提交于 2021-02-10 04:59:07
问题 I am trying to assemble and link this tiny x86 assembly code in Linux (Ubuntu 18.04 LTS): ;hello.asm global _start extern scanf, printf, exit section .data read_name db '%255s', 0 msg db 'Hello, %s', 0 section .text _start: sub esp, 256 push esp push read_name call scanf add esp, 8 push esp push msg call printf add esp, 264 push dword 0 call exit I am using nasm to assemble and ld to link. As you can probably tell, the code uses C functions, so it has to be linked to glibc . Since my code is

How to round to an integer without branching in assembly?

安稳与你 提交于 2021-02-10 03:07:06
问题 How do I round an integer to the nearest whole in assembly? The use of branching is not allowed here. For example, 195 * .85 = 165.75. Normally, I'd multiply 195 by a scale factor (100) and then multiply, then divide down the scale factor. This would give me 165. How do I get 166? I'm sorry if this is a terrible question - I'm new to assembly! Thank you. 回答1: For example, 195 * .85 = 165.75. Normally, I'd multiply 195 by a scale factor (100) and then multiply, then divide down the scale

How to round to an integer without branching in assembly?

不羁岁月 提交于 2021-02-10 03:07:04
问题 How do I round an integer to the nearest whole in assembly? The use of branching is not allowed here. For example, 195 * .85 = 165.75. Normally, I'd multiply 195 by a scale factor (100) and then multiply, then divide down the scale factor. This would give me 165. How do I get 166? I'm sorry if this is a terrible question - I'm new to assembly! Thank you. 回答1: For example, 195 * .85 = 165.75. Normally, I'd multiply 195 by a scale factor (100) and then multiply, then divide down the scale

How to round to an integer without branching in assembly?

♀尐吖头ヾ 提交于 2021-02-10 03:05:46
问题 How do I round an integer to the nearest whole in assembly? The use of branching is not allowed here. For example, 195 * .85 = 165.75. Normally, I'd multiply 195 by a scale factor (100) and then multiply, then divide down the scale factor. This would give me 165. How do I get 166? I'm sorry if this is a terrible question - I'm new to assembly! Thank you. 回答1: For example, 195 * .85 = 165.75. Normally, I'd multiply 195 by a scale factor (100) and then multiply, then divide down the scale

Can't understand assembly mov instruction between register and a variable

点点圈 提交于 2021-02-10 00:36:30
问题 I am using NASM assembler on linux 64 bit. There is something with variables and registers I can't understand. I create a variable named "msg": msg db "hello, world" Now when I want to write to the stdout I move the msg to rsi register, however I don't understand the mov instruction bitwise ... the rsi register consists of 64 bit , while the msg variable has 12 symbols which is 8 bits each , which means the msg variable has a size of 12 * 8 bits , which is greater than 64 bits obviously. So