assembly

NASM Assembler, how to define label twice?

本小妞迷上赌 提交于 2020-05-23 10:53:03
问题 I have different "*.asm" files that need to be included in the "main.asm" file. The problem I'm facing is that: In many files I have declared labels like "loop", "forLoop", "whileTag" etc... in the same way ( i.e. with the same name ) And when I try to %include "file1.asm" and %include "file2.asm" it gives me a compilation error. It says that I can't declare the same label twice ( i.e. file1.asm and file2.asm, both have "loopHere" label declared ). How do I solve this ? Thanks The problem

repz ret: why all the hassle?

拈花ヽ惹草 提交于 2020-05-23 09:44:12
问题 The issue of the repz ret has been covered here [1] as well as in other sources [2, 3] quite satisfactorily. However, reading neither of these sources, I found answers to the following: What is the actual penalty in a quantitative comparison with ret or nop; ret ? Especially in the latter case – is decoding one extra instruction (and an empty one at that!) really relevant, when most functions either have 100+ of those or get inlined? Why did this never get fixed in AMD K8, and even made its

How does the CPU decode variable length instructions correctly?

半世苍凉 提交于 2020-05-23 07:34:29
问题 On most architectures, instructions are all fixed-length. This makes program loading and executing straightforward. On x86/x64, instructions are variable length, so a disassembled program might look like this: File Type: EXECUTABLE IMAGE 00401000: 8B 04 24 mov eax,dword ptr [esp] 00401003: 83 C4 04 add esp,4 00401006: FF 64 24 FC jmp dword ptr [esp-4] 0040100A: 55 push ebp 0040100B: E8 F0 FF FF FF call 00401000 00401010: 50 push eax 00401011: 68 00 30 40 00 push 403000h 00401016: E8 0D 00 00

Assembly executing a long jump with an offset with different syntax

為{幸葍}努か 提交于 2020-05-23 06:53:34
问题 I am writing a GDT for a Kernel and all is going well, I'm following this tutorial. http://www.osdever.net/bkerndev/Docs/gdt.htm When link the C code to the assembly code he uses this piece of code. ; This will set up our new segment registers. We need to do ; something special in order to set CS. We do what is called a ; far jump. A jump that includes a segment as well as an offset. ; This is declared in C as 'extern void gdt_flush();' global _gdt_flush ; Allows the C code to link to this

mirror bits of a 32 bit word

烂漫一生 提交于 2020-05-23 06:07:51
问题 How would you do that in C? (Example: 10110001 becomes 10001101 if we had to mirror 8 bits). Are there any instructions on certain processors that would simplify this task? 回答1: It's actually called "bit reversal", and is commonly done in FFT scrambling. The O(log N) way is (for up to 32 bits): uint32_t reverse(uint32_t x, int bits) { x = ((x & 0x55555555) << 1) | ((x & 0xAAAAAAAA) >> 1); // Swap _<>_ x = ((x & 0x33333333) << 2) | ((x & 0xCCCCCCCC) >> 2); // Swap __<>__ x = ((x & 0x0F0F0F0F)

mirror bits of a 32 bit word

守給你的承諾、 提交于 2020-05-23 06:07:06
问题 How would you do that in C? (Example: 10110001 becomes 10001101 if we had to mirror 8 bits). Are there any instructions on certain processors that would simplify this task? 回答1: It's actually called "bit reversal", and is commonly done in FFT scrambling. The O(log N) way is (for up to 32 bits): uint32_t reverse(uint32_t x, int bits) { x = ((x & 0x55555555) << 1) | ((x & 0xAAAAAAAA) >> 1); // Swap _<>_ x = ((x & 0x33333333) << 2) | ((x & 0xCCCCCCCC) >> 2); // Swap __<>__ x = ((x & 0x0F0F0F0F)

mirror bits of a 32 bit word

不想你离开。 提交于 2020-05-23 06:07:02
问题 How would you do that in C? (Example: 10110001 becomes 10001101 if we had to mirror 8 bits). Are there any instructions on certain processors that would simplify this task? 回答1: It's actually called "bit reversal", and is commonly done in FFT scrambling. The O(log N) way is (for up to 32 bits): uint32_t reverse(uint32_t x, int bits) { x = ((x & 0x55555555) << 1) | ((x & 0xAAAAAAAA) >> 1); // Swap _<>_ x = ((x & 0x33333333) << 2) | ((x & 0xCCCCCCCC) >> 2); // Swap __<>__ x = ((x & 0x0F0F0F0F)

Why is 0 moved to stack when using return value?

假如想象 提交于 2020-05-22 06:46:41
问题 I'm experimenting disassembling clang binaries of simple C programs (compiled with -O0 ), and I'm confused about a certain instruction that gets generated. Here are two empty main functions with standard arguments, one of which returns value and other does not: // return_void.c void main(int argc, char** argv) { } // return_0.c int main(int argc, char** argv) { return 0; } Now, when I disassemble their assemblies, they look reasonably different, but there's one line that I don't understand:

MIPS Basic For Loop

孤街浪徒 提交于 2020-05-17 07:05:12
问题 im trying to implement this java code into MIPS assembly language and i am quite confused. this is what i have so far: java code: for (int c = 1; c <= rows; c++) { number = highestValue; // reset number to the highest value from previous line for (i = 0; i < c; i++) { System.out.print(++number + " "); } highestValue = number; // setting the highest value in line assembly code: .text # tells the program where the code begins move $t0, $zero # t0=0 move $t1, $zero # this will be similar to "int

MIPS Basic For Loop

Deadly 提交于 2020-05-17 07:04:49
问题 im trying to implement this java code into MIPS assembly language and i am quite confused. this is what i have so far: java code: for (int c = 1; c <= rows; c++) { number = highestValue; // reset number to the highest value from previous line for (i = 0; i < c; i++) { System.out.print(++number + " "); } highestValue = number; // setting the highest value in line assembly code: .text # tells the program where the code begins move $t0, $zero # t0=0 move $t1, $zero # this will be similar to "int