assembly

Accessing the Program Segment Prefix

回眸只為那壹抹淺笑 提交于 2021-02-08 07:34:47
问题 I'm trying to access the Program Segment Prefix (PSP) in x86 MASM Assembler. As a test, I'd like to print the given command line arguments after running my program. I tried putting the address of the PSP in the dx register, with an offset of 81h : the position of the command line arguments. However, after running the program, I get this in return. I can see the given command line argument, but it is preceded by a lot of gibberish. Any idea why this is happening? I guess I'm not correctly

print string with bios interrupt 0x10

拈花ヽ惹草 提交于 2021-02-08 07:10:33
问题 I want to print a string using bios interrupt 0x10. But I get only a blue fiel, without letters in it. Maybe I habe a problem by adressing my string. Edit: I have two code files. The first is written on the first sector of a floppy. It copys the second sector from the floppy to the memory (starting at 0x5000) and jump to 0x5000. Here is my second file, where I should print my string. [BITS 16] org 0x5000 sect2: mov ah, 0x03 ;get curser position mov bh, 0x00 ;page number int 0x10 mov ax,

About negate a sign-integer in mips?

瘦欲@ 提交于 2021-02-08 06:57:22
问题 I'm thinking about how to negate a signed-integer in mips32. My intuition is using definition of 2's complement like: (suppose $s0 is the number to be negated) nor $t0, $s0, $s0 ; 1's complement addiu $t0, $t0, 1 ; 2's = 1's + 1 then I realized that it can be done like: sub $t0, $zero, $s0 so... what's the difference? Which is faster? IIRC sub will try to detect overflow, but would this make is slower? Finally, is there any other way to do so? 回答1: subu $t0, $zero, $s0 is the best way, and is

int 13h doesn't appear to read sectors containing my kernel

眉间皱痕 提交于 2021-02-08 05:07:19
问题 I am trying to load up a little data using my bootloader on a USB, but apparently int 13h won't work! Bootloader: [bits 16] [ORG 0x7c00] jmp 0x0000:start start: cli xor ax, ax mov ss, ax mov sp, 0x7c00 mov ax, cs mov ds, ax mov es, ax mov fs, ax mov gs, ax sti mov [driveno], dl reset: ;reset drive xor ax, ax mov dl, [driveno] int 0x13 or ah, ah jnz reset mov ah, 0x02 mov al, 0x01 mov bx, 0x0000 mov es, bx mov bx, 0x7e00 mov dl, [driveno] xor dh, dh mov cx, 0x0002 int 0x13 or ah, ah jnz reset

Inline assembly - cdecl and preparing the stack

时间秒杀一切 提交于 2021-02-08 04:50:42
问题 I've recently been trying to implement dynamic functions in C++ by using a buffer and RAW hexadecimal equivalents of different assembly operators. To illustrate a simple jump: byte * buffer = new buffer[5]; *buffer = '0xE9'; // Hex for jump *(uint*)(buffer + 1) = 'address destination'; I am not experienced in assembly but I know enough to create very simple functions. Right now I'm creating cdecl functions in raw memory. The problem is, I do not know how much I want to push the stack (for

GCC + LD + NDISASM = huge amount of assembler instructions

天涯浪子 提交于 2021-02-08 04:43:21
问题 I'm a newbie to C and GCC compilers and trying to study how C is compiled into machine code by disassembling binaries produced, but the result of compiling and then disassembling a very simple function seems overcomplicated. I have basic.c file: int my_function(){ int a = 0xbaba; int b = 0xffaa; return a + b; } Then I compile it using gcc -ffreestanding -c basic.c -o basic.o And when I dissasemble basic.o object file I get quite an expected output: 0000000000000000 <my_function>: 0: 55 push

Using assembly code written for 32-bit in 64-bit application

血红的双手。 提交于 2021-02-08 04:17:07
问题 Can I use the assembly routines for Serpent encryption in the link below written for 32-bit x86 from a 64-bit program on an x86-64 machine? That is, without launching a separate 32-bit process for it? If not, does anyone have a pointer to an optimized implementation of Serpent that works in both 32 and 64 bit (LGPL is OK but cannot use GPL since it's a commercial project)? http://gladman.plushost.co.uk/oldsite/cryptography_technology/serpent/serpent.asm 回答1: You will need to convert the

Using assembly code written for 32-bit in 64-bit application

依然范特西╮ 提交于 2021-02-08 04:11:14
问题 Can I use the assembly routines for Serpent encryption in the link below written for 32-bit x86 from a 64-bit program on an x86-64 machine? That is, without launching a separate 32-bit process for it? If not, does anyone have a pointer to an optimized implementation of Serpent that works in both 32 and 64 bit (LGPL is OK but cannot use GPL since it's a commercial project)? http://gladman.plushost.co.uk/oldsite/cryptography_technology/serpent/serpent.asm 回答1: You will need to convert the

In x86 assembly, when should I use global variables instead of local variables?

梦想的初衷 提交于 2021-02-08 03:39:55
问题 I am creating some small programs with x86 assembly, and it's my first time using a low level language so I'm not used to it. In high level languages I rarely use global variables, but I've seen a lot of tutorials using global variables in assembly, so I'm not sure when to use global variables instead of local variables. By global variables I mean data created in the .bss and .data segments, and by local variables I mean data allocated on the stack of the current procedure, using the stack

Calculate absolute difference |A-B| in assembly using only INC, DEC, JNZ, HALT - interview question

泄露秘密 提交于 2021-02-08 03:31:55
问题 This is a question I encountered in an interview and for which I didn't find a solution - so I tried to solve it myself. We can use pseudocode here - it doesn't need to be a formal code. The question is to get the absolute difference of unsigned inputs: Assume your assembly language includes ONLY the following instructions: inc , dec , jnz and halt ( halt = stop running). Task: A and B are registers that hold non-negative values. The program should calculate the value of |A-B| and locate the