assembly

x86 assembly - printing a character given an ascii code

心已入冬 提交于 2020-05-15 09:18:40
问题 I am new to assembly programming and am having trouble printing a character to the screen. Every time I execute my program I get a segmentation fault and I am not sure why. .section .data A: .long 65 # ascii code for 'A' .section .text .globl _start _start: movl $1, %edx # length of character to print, 1 movl A, %ecx # what I want printed movl $1, %ebx # file descriptor for STDOUT movl $4, %eax # syscall number for sys_write int $0x80 # calls kernel movl $0, %ebx # return status movl $1, %eax

How to move a floating-point constant value into an xmm register?

烂漫一生 提交于 2020-05-15 08:33:22
问题 Is the only way to move a value into an xmm register by first moving the value into an integer register, dunno what they are called, and then into the xmm register e.g. mov [eax], (float)1000 ; store to memory movss xmm1,[eax] ; reload or mov eax, 1000 ; move-immediate integer cvtsi2ss xmm1,eax ; and convert or is there another way? Is there a way to directly move a value into a xmm register, something along the lines of: movss xmm1,(float)1000 ? 回答1: There are no instructions to load an SSE

Using intel inline assembler to code bigint add with carry

只谈情不闲聊 提交于 2020-05-15 07:19:08
问题 I would like to do a fast code for adding 64 bit numbers in big ints: uint64_t ans[n]; uint64_t a[n], b[n]; // assume initialized values.... for (int i = 0; i < n; i++) ans[i] = a[i] + b[i]; but the above does not work with carry. I saw another question here that suggested using an if statement to check which is elegant: ans[0] = a[0] + b[0]; int c = ans[0] < a[0]; for (int i = 0; i < n; i++) { ans[i] = a[i] + b[i] + c; c = ans[i] < a[i]; } However, I would like to learn how to embed inline

Using intel inline assembler to code bigint add with carry

橙三吉。 提交于 2020-05-15 07:18:27
问题 I would like to do a fast code for adding 64 bit numbers in big ints: uint64_t ans[n]; uint64_t a[n], b[n]; // assume initialized values.... for (int i = 0; i < n; i++) ans[i] = a[i] + b[i]; but the above does not work with carry. I saw another question here that suggested using an if statement to check which is elegant: ans[0] = a[0] + b[0]; int c = ans[0] < a[0]; for (int i = 0; i < n; i++) { ans[i] = a[i] + b[i] + c; c = ans[i] < a[i]; } However, I would like to learn how to embed inline

Cannot call real mode C function from bootloader (NASM + GCC toolchain)

北城余情 提交于 2020-05-15 06:56:05
问题 I am attempting to write my own OS kernel, and have been having some issues getting the linking to work properly between my bootloader and (what will soon be) my kernel (written in C). I have the following code... src/bootloader.asm ; Allows our code to be run in real mode. BITS 16 extern kmain section .text global _start _start: jmp Start ; Moves the cursor to row dl, col dh. MoveCursor: mov ah, 2 mov bh, 0 int 10h ret ; Prints the character in al to the screen. PrintChar: mov ah, 10 mov bh,

How does the CPU know how many bytes it should read for the next instruction, considering instructions have different lenghts?

删除回忆录丶 提交于 2020-05-15 06:54:05
问题 So i was reading a paper, and in it, they said that statically disassembling the code of a binary is undecidable, because a series of bytes could be represented as many possible ways as shown in picture ( its x86 ) so my question is : how does the CPU execute this then? for example in the picture, when we reach after C3, how does it know how many bytes it should read for the next instruction? how does the CPU know how much it should increment the PC after executing one instruction? does it

OpenOCD and stm32f7 writing

巧了我就是萌 提交于 2020-05-14 06:02:23
问题 So i have a very minimal code just to see if device is alive. section .text .weak Reset_Handler Reset_Handler: ldr r0, =_estack mov sp, r0 /* set stack pointer */ ldr r2, =_sdata // b Reset_Handler According to datasheet, flash starts from 0x0800 0000 on axim bus. here is my linker file ENTRY(Reset_Handler) MEMORY { RAM (xrw) : ORIGIN = 0x20020000, LENGTH = 368K ROM (rx) : ORIGIN = 0x08000000, LENGTH = 2048K } _estack = ORIGIN(RAM)+LENGTH(RAM); SECTIONS { .text : { . = ALIGN(4); *(.text) . =

OpenOCD and stm32f7 writing

◇◆丶佛笑我妖孽 提交于 2020-05-14 05:59:07
问题 So i have a very minimal code just to see if device is alive. section .text .weak Reset_Handler Reset_Handler: ldr r0, =_estack mov sp, r0 /* set stack pointer */ ldr r2, =_sdata // b Reset_Handler According to datasheet, flash starts from 0x0800 0000 on axim bus. here is my linker file ENTRY(Reset_Handler) MEMORY { RAM (xrw) : ORIGIN = 0x20020000, LENGTH = 368K ROM (rx) : ORIGIN = 0x08000000, LENGTH = 2048K } _estack = ORIGIN(RAM)+LENGTH(RAM); SECTIONS { .text : { . = ALIGN(4); *(.text) . =

Confusion with how Win32 API calls work in assembly

孤人 提交于 2020-05-13 06:46:50
问题 I don't know how to ask this better but why does this: call ExitProcess do the same as this?: mov eax, ExitProcess mov eax, [eax] call eax I would think that these would be equivalent: call ExitProcess mov eax, ExitProcess call eax 回答1: When importing the code from a DLL, the symbol ExitProcess isn't actually the address of the code that exits your process (it's the address of the address ). So, in that case, you have to dereference it to get the actual code address. That means that you must

What is clang trying to do optimizing this simple recursive algorithm?

佐手、 提交于 2020-05-12 19:52:38
问题 Upon writing an answer to this question: Using variable vs. using number I ran clang x86 9.0.0/trunk with -O3 to see if it could do tail-call optimization of this simple code: int faculty1 (const unsigned int n) { return n == 1 ? n : n * faculty1(n - 1); } Not only does clang fail that, it goes completely bananas and gives me this: godbolt .LCPI0_0: .long 0 # 0x0 .long 4294967295 # 0xffffffff .long 4294967294 # 0xfffffffe .long 4294967293 # 0xfffffffd .LCPI0_1: .long 1 # 0x1 .long 1 # 0x1