assembly

Multiplying 32 bit two numbers on 8086 microprocessor

僤鯓⒐⒋嵵緔 提交于 2020-03-16 07:25:57
问题 I have code example for multiplying two 16 bit numbers on 8086 and trying to update it for two 32 bit numbers multiplying. start: MOV AX,0002h ; 16 bit multiplicand MOV BX,0008h ; 16 bit multiplier MOV DX,0000h ; high 16 bits of multiplication MOV CX,0000h ; low 16 bits of multiplication MOV SI,10h ; loop for 16 times LOOP: MOV DI,AX AND DI,01h XOR DI,01h JZ ADD CONT: RCR DX,1 RCR CX,1 SHR AX,1 DEC SI CMP SI,0 JNZ LOOP JMP END ; ignore here, it's not about multiplication. ADD: ADD DX,BX JMP

Segfault with x86 assembly on mov 0, %eax

一笑奈何 提交于 2020-03-16 06:00:13
问题 I'm trying to assemble a small piece of x86 code. I'm on a 32 bit machine and I have written the following code. It should just add values into eax and then return. I realize there will not be any output. When I compile this using gcc main.S -o main It compiles with no errors. But when I run it seg faults (gdb claims that it segfaults on the first movl instruction). main.S has the following code in it. What am I doing wrong? .text .globl main main: pushl %ebp movl %esp, %ebp movl 0, %eax addl

What's the size of a QWORD on a 64-bit machine?

让人想犯罪 __ 提交于 2020-03-15 05:41:08
问题 I'm currently looking to find an answer to the above question. So far I found people saying, that the word size refers to the size of a processor register, which would suggest on a 64-bit machine the word size being 64 bits and thus a QWORD (4 * word) being 256 bits in size. But on the other hand I found sources like this saying the size would be 128 bits (64 bits for 32-bit and doubled this for 64-bit), while even then others suggest the size would be 64 bits. But the last one is somehow

Adding values in C using inline assembly

拟墨画扇 提交于 2020-03-14 18:29:22
问题 Im trying to get a grasp on the basics of inline assembly in C (ATT assembly), so Im practicing by adding 2 variables. Ok so this works as intended; the src variable gets copied to the dst variable and then the dst variable gets added by 5. The values of src and dst are 1 and 6 respectively. int src = 1; int dst = 0; asm ("mov %[SRC], %[DEST]\n\t" "add $5, %0" : [DEST] "=r" (dst)); : [SRC] "r" (src)); But when I try this out, the values of src and dst are still 1 and 6. I was expecting src to

What meaning, if any, does the Mod R/M byte carry for the unconditional jump instruction 0xFF?

江枫思渺然 提交于 2020-03-14 07:39:20
问题 Consider the following code, compiled on a 32-bit Ubuntu 14.04.2 with gcc 4.8.2 #include <unistd.h> int main(){ _exit(0); } If I open this code in gdb and run disas /r _exit , I get the following. (gdb) disas /r _exit Dump of assembler code for function _exit@plt: 0x080482f0 <+0>: ff 25 0c a0 04 08 jmp *0x804a00c 0x080482f6 <+6>: 68 00 00 00 00 push $0x0 0x080482fb <+11>: e9 e0 ff ff ff jmp 0x80482e0 End of assembler dump. (gdb) The Intel manual tells us that ff is the opcode for JMP , while

How do I add binary numbers using ARM Assembly?

泪湿孤枕 提交于 2020-03-04 19:35:49
问题 The assembly language that I"m using is ARM Assembly. Would I use the ADD instruction to do so? Would I have to start by taking in a number in decimal and then using some instruction to convert the decimal number to binary? Let's say that I have three numbers 33, 25, and 14. I want to add them all together. Say that the three numbers are stored in an 8-bit array with binary numbers with three elements. After traversing through the array, would I have to convert the binary numbers to decimal

Garbage in string output function

China☆狼群 提交于 2020-03-04 08:31:09
问题 I'm trying to write a printf replacement in asm and so far have this code: ; string is loaded into r8 print_string: push rax push rbx push rsi push rdx ; load string pointer into ecx mov rsi, r8 ; loop over every char print_string_loop0: cmp sil, 0 ; stop when encounter null character je print_string_return mov rax, 1 ; syscall (sys_write) mov rdi, 1 ; file descriptor for write (stdout = 1) mov rdx, 1 ; bytes to write (1 character) syscall inc rsi jmp print_string_loop0: print_string_return:

Garbage in string output function

半世苍凉 提交于 2020-03-04 08:30:30
问题 I'm trying to write a printf replacement in asm and so far have this code: ; string is loaded into r8 print_string: push rax push rbx push rsi push rdx ; load string pointer into ecx mov rsi, r8 ; loop over every char print_string_loop0: cmp sil, 0 ; stop when encounter null character je print_string_return mov rax, 1 ; syscall (sys_write) mov rdi, 1 ; file descriptor for write (stdout = 1) mov rdx, 1 ; bytes to write (1 character) syscall inc rsi jmp print_string_loop0: print_string_return:

Purpose of rdi register for no argument function

别来无恙 提交于 2020-03-04 05:03:40
问题 Consider this simple function: struct Foo { int a; int b; int c; int d; int e; int f; }; Foo foo() { Foo f; f.a = 1; f.b = 2; f.c = 3; f.d = 4; f.e = 5; f.f = 6; return f; } It generates the following assembly: 0000000000400500 <foo()>: 400500: 48 ba 01 00 00 00 02 movabs rdx,0x200000001 400507: 00 00 00 40050a: 48 b9 03 00 00 00 04 movabs rcx,0x400000003 400511: 00 00 00 400514: 48 be 05 00 00 00 06 movabs rsi,0x600000005 40051b: 00 00 00 40051e: 48 89 17 mov QWORD PTR [rdi],rdx 400521: 48

memset movq giving segfault

女生的网名这么多〃 提交于 2020-03-04 05:03:13
问题 I've been stuck with the gdb for a few hours now. I am getting a segfault at the movq (%rsi, %rcx) line. I know you can't do mem->mem mov, so I did it through a temporary register. (%rsi), %rcx, then in the loop %rcx, (%rdi). Here is my code: experimentMemset: #memset(void *ptr, int value, size_t num) #%rdi #%rsi #%rdx movq %rdi, %rax #sets rax to the first pointer, to return later .loop: cmp $0, (%rdx) #see if num has reached 0 je .end cmpb $0, (%rdi) #see if string has ended also je .end