assembly

Why does my assembly program (x86) freezes in Dosbox when I try to run it?

帅比萌擦擦* 提交于 2020-06-09 07:04:30
问题 Things to note: Working in x86 assembly (16-bit); using Nasm; running program in DosBox. When I try to run the program in DosBox, the emulator freezes (I'm not sure freezes is the right word since the cursor still blinks) and refuses to respond to input. The first time I tried running it DosBox actually crashed. Here is my code: ;ASSIGNMENT 3 org 100h section.data: prompt1 db 0dh, 0ah, 0dh, 0ah, "Please input a signed base-10 integer: $" prompt2 db 0dh, 0ah, "Your number in binary is: $"

Why does my assembly program (x86) freezes in Dosbox when I try to run it?

China☆狼群 提交于 2020-06-09 07:01:28
问题 Things to note: Working in x86 assembly (16-bit); using Nasm; running program in DosBox. When I try to run the program in DosBox, the emulator freezes (I'm not sure freezes is the right word since the cursor still blinks) and refuses to respond to input. The first time I tried running it DosBox actually crashed. Here is my code: ;ASSIGNMENT 3 org 100h section.data: prompt1 db 0dh, 0ah, 0dh, 0ah, "Please input a signed base-10 integer: $" prompt2 db 0dh, 0ah, "Your number in binary is: $"

GNU GAS: Label is not relatively referenced

烈酒焚心 提交于 2020-06-09 04:32:30
问题 I am writing a little bootsector for learning purpose. Here is boot.S .code16 .text movw $0xB800, %ax /* 0xB000 is the text screen video memory */ movw %ax, %es /* set it as the %es segment */ movb label, %al movb %al, %es:0x0 /* screen[0] = 'A' */ movb $0x07, %es:0x1 /* white on black */ jmp . label: .byte 'A .=510 .byte 0x55 .byte 0xAA and here is the Makefile I use to compile it to a raw binary file hdd.img: boot.S as $< -o boot.o ld --oformat binary -Ttext 0x7c00 boot.o -o hdd.img I face

How does this x86 Assembly code create a string?

女生的网名这么多〃 提交于 2020-06-09 04:28:05
问题 I'm studying the x86 assembly language. In order to better understand what's going on behind the scenes of string creation, I have a sample program that just prints a string. GCC produced the following Assembly program, and I'm having trouble understanding the compiler's output: Assembly Code: Dump of assembler code for function main: 0x0000000000400596 <+0>: push %rbp 0x0000000000400597 <+1>: mov %rsp,%rbp 0x000000000040059a <+4>: sub $0x10,%rsp 0x000000000040059e <+8>: movq $0x400668,-0x8(

Linker error when calling printf from _start [duplicate]

為{幸葍}努か 提交于 2020-06-09 04:17:28
问题 This question already has answers here : Assembling 32-bit binaries on a 64-bit system (GNU toolchain) (2 answers) Closed 3 years ago . I tried to write simple program without main segment .data fmt db "test", 0xa, 0 segment .text global _start extern printf _start: lea rdi, [fmt] ; print simple string xor eax, eax call printf mov eax, 60 ; exit successfully xor edi, edi syscall Compile: yasm -f elf64 main.s; ld -o main main.o Got main.o: In function `_start': main.s:(.text+0xb): undefined

Linker error when calling printf from _start [duplicate]

浪尽此生 提交于 2020-06-09 04:17:06
问题 This question already has answers here : Assembling 32-bit binaries on a 64-bit system (GNU toolchain) (2 answers) Closed 3 years ago . I tried to write simple program without main segment .data fmt db "test", 0xa, 0 segment .text global _start extern printf _start: lea rdi, [fmt] ; print simple string xor eax, eax call printf mov eax, 60 ; exit successfully xor edi, edi syscall Compile: yasm -f elf64 main.s; ld -o main main.o Got main.o: In function `_start': main.s:(.text+0xb): undefined

Why does C not push a pointer on the stack when calling a assembly function?

落爺英雄遲暮 提交于 2020-06-09 02:47:11
问题 I am currently trying to get some experience with calling assembly functions from C. Therefore, I created a little program which calculates the sum of all array elements. The C Code looks like this: #include <stdio.h> #include <stdint.h> extern int32_t arrsum(int32_t* arr,int32_t length); int main() { int32_t test[] = {1,2,3}; int32_t length = 3; int32_t sum = arrsum(test,length); printf("Sum of arr: %d\n",sum); return 0; } And the assembly function looks like this: .text .global arrsum

X86 encode near call relative offset

丶灬走出姿态 提交于 2020-06-08 18:58:52
问题 Let's say I've the following set of instructions: 00E79E00 | E8 AE580000 CALL someprocess.00E7F6B3 00E79E05 | 85C0 TEST EAX, EAX (output taken from OllyDbg) How do I encode the rel32 offset from the near call(0xE8) so I can get the absolute position I can jump to? I know that the offset is relative to the next instruction and is calculated by subtracting the target with it. My question is: how do I 'reverse' this so I get the function addres 00E7F6B3 from the relative offset AE580000 回答1: You

X86 encode near call relative offset

谁都会走 提交于 2020-06-08 18:58:27
问题 Let's say I've the following set of instructions: 00E79E00 | E8 AE580000 CALL someprocess.00E7F6B3 00E79E05 | 85C0 TEST EAX, EAX (output taken from OllyDbg) How do I encode the rel32 offset from the near call(0xE8) so I can get the absolute position I can jump to? I know that the offset is relative to the next instruction and is calculated by subtracting the target with it. My question is: how do I 'reverse' this so I get the function addres 00E7F6B3 from the relative offset AE580000 回答1: You

How to execute a call instruction with a 64-bit absolute address?

旧城冷巷雨未停 提交于 2020-06-08 06:14:05
问题 I am trying to call a function - that should have an absolute address when compiled and linked - from machine code. I am creating a function pointer to the desired function and trying to pass that to the call instruction, but I noticed that the call instruction takes at most a 16 or 32-bit address. Is there a way to call an absolute 64-bit address? I am deploying for the x86-64 architecture and using NASM to generate the machine code. I could work with a 32-bit address if I could be