nasm

x86 Assembly, getting segmentation fault

人走茶凉 提交于 2019-12-20 07:37:47
问题 section .data msg: db "hello!", 10, 0 ;my message section .text extern printf ;C printf function global main main: push ebp mov ebp, esp call print_string mov esp, ebp pop ebp ret ;end of program print_string: pusha push msg call printf ;should print "Hello" popa ret ;return back to main When I run this code I get: hello! Segmentation fault (core dumped) What is wrong with the code? 回答1: The print_string subroutine is modifying the stack pointer without restoring it. The subroutine main has

Using FPU return values in c++ code

萝らか妹 提交于 2019-12-20 07:27:15
问题 I have an x86 NASM program which seems to work perfectly. I have problems using the values returned from it. This is 32-Bit Windows using MSVC++. I expect the return value in ST0 . A minimal example demonstrating the problem with the returned values can be seen in this C++ and NASM assembly code: #include <iostream> extern "C" float arsinh(float); int main() { float test = arsinh(5.0); printf("%f\n", test); printf("%f\n", arsinh(5.0)); std::cout << test << std::endl; std::cout << arsinh(5.0)

Shutting down computer with nasm

青春壹個敷衍的年華 提交于 2019-12-20 07:26:43
问题 Is it possible to shut down or kill the power (is there a difference?) to a computer from nasm. I know you can use this to reboot: mov al, 0xFE out 0x64, al Is there an equivalent for shutting down? I am making my own 16 bit OS. 回答1: The code you have is not guaranteed to work. It relies on two facts: the OS maps the physical IO memory into the process memory space. the machine has BIOS. Neither of the two might be true. The only reliable way to reboot or shutdown the machine programatically

linux nasm assembly print all numbers from zero to 100

无人久伴 提交于 2019-12-20 07:15:12
问题 I am writing a program to print out all the numbers from zero to 100. The only reason I am doing this is to test out printing out multiple digit numbers. The problem that I am having is that my program is only printing out the numbers 1 and 2. I have no idea why. My compiler compiles fine, without error, as well as no linker errors. Here is my code: SECTION .data len EQU 32 NUL EQU 0 countlen EQU 8 SECTION .bss counter resb countlen strlen resb countlen SECTION .text GLOBAL _start _start: mov

Are the data registers EAX, EBX, ECX and EDX interchangeable

血红的双手。 提交于 2019-12-20 06:55:52
问题 I'm stepping into the world of Assembly Language Programming. I'm trying to understand everything found on: https://www.tutorialspoint.com/assembly_programming I came across the code below. section .text global _start ;must be declared for using gcc _start: ;tell linker entry point ;This part works fine. ;mov edx, len ;message length ;mov ecx, msg ;message to write ;This does not work because I interchanged edx and ecx. mov ecx, len ;message length mov edx, msg ;message to write mov ebx, 1

Error when calling function in user32.dll directly

风格不统一 提交于 2019-12-20 06:29:36
问题 I read an article some time ago from a guy who demonstrated how one can directly call a function in user32.dll in assembly (NASM) by its memory address. I do not have the article anymore but I'm trying to reproduce the experiment. The function I want to execute is MessageBoxA in user32.dll and on my computer, the function should be located at the address 0x76cd75c0. Here is the function: int MessageBoxA( HWND hWnd, # NULL LPCSTR IpText, # text LPCSTR IpCaption, # title UINT uType # style );

NASM: Far Call with Segment and Offset Stored in Registers

感情迁移 提交于 2019-12-20 05:39:19
问题 I've got the code segment and the offset values stored in two registers, say AX and BX respectively. In NASM how can I encode a far call to AX:BX ? I tried call AX:BX , but I got the error invalid combination of opcode and operands . How do I encode this instruction? 回答1: There isn't a way to encode a far call instruction where the segment and/or offset are in registers. The far call instruction requires that the destination either be given as an immediate operand that supplies both the

NASM/Yasm drops CALL after comment ending with backslash

穿精又带淫゛_ 提交于 2019-12-20 05:28:07
问题 I am currently trying to built my own boot loader and noticed something peculiar. When below code is assembled with NASM or Yasm without the marked NOP command the following CALL is missing from the binary. With the NOP included the CALL is correctly assembled but the op code 0x90 (NOP) is not present in the binary (later is understandable due to the nature of NOP). to_hex_ascii: add al, '0' cmp al, 0x3a jl .end ; add al, 0x07 add al, 0x27 .end: ret print_word_hex: push bp mov bp, sp mov dx,

x64 bit assembly

天大地大妈咪最大 提交于 2019-12-20 05:21:49
问题 I started assembly (nasm) programming not too long ago. Now I made a C function with assembly implementation which prints an integer. I got it working using the extended registers, but when I want to write it with the x64 registers (rax, rbx, ..) my implementation fails. Does any of you see what I missed? main.c: #include <stdio.h> extern void printnum(int i); int main(void) { printnum(8); printnum(256); return 0; } 32 bit version: ; main.c: http://pastebin.com/f6wEvwTq ; nasm -f elf32 -o

x64 bit assembly

≡放荡痞女 提交于 2019-12-20 05:21:42
问题 I started assembly (nasm) programming not too long ago. Now I made a C function with assembly implementation which prints an integer. I got it working using the extended registers, but when I want to write it with the x64 registers (rax, rbx, ..) my implementation fails. Does any of you see what I missed? main.c: #include <stdio.h> extern void printnum(int i); int main(void) { printnum(8); printnum(256); return 0; } 32 bit version: ; main.c: http://pastebin.com/f6wEvwTq ; nasm -f elf32 -o