assembly

Why bubble sort is not efficient?

走远了吗. 提交于 2021-02-05 07:14:08
问题 I am developing backend project using node.js and going to implement sorting products functionality. I researched some articles and there were several articles saying bubble sort is not efficient. Bubble sort was used in my previous projects and I was surprised why it is bad. Could anyone explain about why it is inefficient? If you can explain by c programming or assembler commands it would be much appreciated. 回答1: Bubble Sort has O(N^2) time complexity so it's garbage for large arrays

What happens for a RIP-relative load next to the current instruction? Cache hit?

旧街凉风 提交于 2021-02-05 07:11:25
问题 I am reading Agner Fog's book on x86 assembly. I am wondering about how RIP-relative addressing works in this scenario. Specifically, assume my RIP offset is +1. This suggests the data I want to read is right next to this instruction in memory. This piece of data is likely already fetched into the L1 instruction cache. Assuming that this data is not also in the L1d, what exactly will happen on the CPU? Let's assume it's a relatively recent Intel architecture like Kaby Lake. 回答1: Yes, it's

Why syscall doesn't work?

若如初见. 提交于 2021-02-05 07:11:07
问题 I'm on MAC OSX and I'm trying to call through assembly the execve syscall.. His opcode is 59 . In linux I have to set opcode into eax, then parameters into the others registers, but here I have to put the opcode into eax and push parameters into the stack from right to left. So I need execve("/bin/sh",NULL,NULL), I found somewhere that with assembly null=0, so I put null into 2nd and 3rd parameters. global start section .text start: jmp string main: ; 59 opcode ; int execve(char *fname, char

What happens for a RIP-relative load next to the current instruction? Cache hit?

核能气质少年 提交于 2021-02-05 07:11:06
问题 I am reading Agner Fog's book on x86 assembly. I am wondering about how RIP-relative addressing works in this scenario. Specifically, assume my RIP offset is +1. This suggests the data I want to read is right next to this instruction in memory. This piece of data is likely already fetched into the L1 instruction cache. Assuming that this data is not also in the L1d, what exactly will happen on the CPU? Let's assume it's a relatively recent Intel architecture like Kaby Lake. 回答1: Yes, it's

Can an x86 CPU read the value of any register while in user mode?

為{幸葍}努か 提交于 2021-02-05 06:54:05
问题 I have read that there are some registers that an x86 CPU cannot modify while in user mode (I believe these registers are called "privileged registers"). But can an x86 CPU read the values of these registers while in user mode, or is even reading not allowed? 回答1: All the registers you'd normally use for computation can be read/written in any mode (GP integer, x87/MMX, XMM/YMM/ZMM and AVX512 k0-7 mask registers), but there are many registers that are basically mode/control settings. Some

Why is GDB breakpoint set at the wrong address for an x86 assembly function?

狂风中的少年 提交于 2021-02-05 06:52:38
问题 I am experiencing an issue where gdb is mapping a line number to the wrong memory address when adding a breakpoint. The following x86 Linux assembly program prints "hello". /* hello.s */ .section .data str: .ascii "hello\n" strlen = . - str .section .text print: pushl %ebp movl %esp, %ebp pushl %ebx movl $4, %eax movl $1, %ebx movl $str, %ecx movl $strlen, %edx int $0x80 popl %ebx movl %ebp, %esp popl %ebp ret .globl _start _start: call print movl $1, %eax movl $0, %ebx int $0x80 I compile it

Merge bit sequences a and b according to a mask

旧街凉风 提交于 2021-02-05 06:52:37
问题 According to the bit twiddling hacks website, the operation unsigned int a; // value to merge in non-masked bits unsigned int b; // value to merge in masked bits unsigned int mask; // 1 where bits from b should be selected; 0 where from a. unsigned int r; // result of (a & ~mask) | (b & mask) goes here r = a ^ ((a ^ b) & mask); allows to merge two bit sequences a and b according to a mask. I was wondering: Whether this operation had a specific/usual name? Whether specific assembly instruction

Merge bit sequences a and b according to a mask

别等时光非礼了梦想. 提交于 2021-02-05 06:52:13
问题 According to the bit twiddling hacks website, the operation unsigned int a; // value to merge in non-masked bits unsigned int b; // value to merge in masked bits unsigned int mask; // 1 where bits from b should be selected; 0 where from a. unsigned int r; // result of (a & ~mask) | (b & mask) goes here r = a ^ ((a ^ b) & mask); allows to merge two bit sequences a and b according to a mask. I was wondering: Whether this operation had a specific/usual name? Whether specific assembly instruction

NASM should I pop function argument after calling a function?

女生的网名这么多〃 提交于 2021-02-05 06:51:29
问题 Let's say I have a nasm function like this: inc: mov rax,[rsp + 8] add [rax],BYTE 1 ret And I am calling this function like this: push some_var call inc I want to pass an argument to the function through the stack, so I push some_var and then call my function. In the function my item is second on the stack so I take it like: mov rax,[rsp+8] My question is: after calling function should I somehow pop my argument from the stack? If so, can I somehow delete it from the stack, I mean pop it, but

Arm Assembly Rasperry-Pi: Converting a string to Upper case

╄→尐↘猪︶ㄣ 提交于 2021-02-05 06:44:15
问题 I´m working on a program in which the user enters his name, and the program should convert all lower case letters to upper case: I am using the %s format to read the string: .text ldr r0,=msj bl printf ldr r0,=format ldr r1,string bl scanf .data .align 2 msj: .asciz "Enter you name: " format: .asciz "%s" string: .asciz "" I have tried substracting 32 to each character but I think the strings are not in ascii numbers format. Is there any way I can convert the entire word to Upper Case? 回答1: