assembly

What is the purpose of the Parity Flag on a CPU?

家住魔仙堡 提交于 2020-11-30 08:22:45
问题 Some CPUs (notably x86 CPUs) feature a parity flag on their status register. This flag indicates whether the number of bits of the result of an operation is odd or even. What actual practical purpose does the parity flag serve in a programming context? Side note: I'm presuming it's intended to be used in conjunction with a parity bit in order to perform basic error checking, but such a task seems to uncommon to warrant an entire CPU flag. 回答1: Back in the "old days" when performance was

Loading a register from a “db 0” doesn't load a 0 into EAX?

旧街凉风 提交于 2020-11-29 10:56:38
问题 I've been bashing my head against the wall for over an hour and I can't understand why the below doesn't work. If I change b: db 1 to b: db 0 then it should print 10, otherwise it should print 0. Instead, the program always prints 10. I've been writing a project that writes assembly and this is one of the unit test that fails and I just don't get it. It has to be something simple. extern printf, exit section .bss section .data b: db 1 x: dd 5 y: dd 5 z: dd 0 int_pattern: db "%i", 10, 0 global

Loading a register from a “db 0” doesn't load a 0 into EAX?

无人久伴 提交于 2020-11-29 10:54:41
问题 I've been bashing my head against the wall for over an hour and I can't understand why the below doesn't work. If I change b: db 1 to b: db 0 then it should print 10, otherwise it should print 0. Instead, the program always prints 10. I've been writing a project that writes assembly and this is one of the unit test that fails and I just don't get it. It has to be something simple. extern printf, exit section .bss section .data b: db 1 x: dd 5 y: dd 5 z: dd 0 int_pattern: db "%i", 10, 0 global

Function that takes a char array and 2 indices; swapping the chars in those indices

邮差的信 提交于 2020-11-29 10:24:54
问题 This is my function prototype: char* swap(char* array, int index1, int index2); This is my assembly code: segment .text global swap swap: mov r14,[rdi+rsi] mov r15,[rdi+rdx] mov [rdi+rsi],r15 ;this line segfaults mov [rdi+rdx],r14 mov rax,rdi ret The lines mov [rdi+rsi],r15 and mov [rdi+rdx],r14 give me a segfault; I'm not sure where I'm going wrong The calling function: #include <stdio.h> #include <stdlib.h> extern char* swapLetters(char* str, int indexA, int indexB); int main() { char* st=

difference of 'INT' instruction between Linux and Windows

一世执手 提交于 2020-11-29 10:13:48
问题 I write some code to make my own operating system and study x86 assembly language, too. While studying x86 assembly language, I start wondering about interrupt. Look at below assembly code: mov ah, 2 mov dl, 'A' int 0x21 This code prints 'A' to the screen. it is for MS-DOS. mov eax, 1 mov ebx, 0 int 0x80 This code makes program to exit. it is for Linux. The last one: mov ah, 2 mov al, 1 mov ch, 0 mov cl, 2 mov dh, 0 mov dl, 0 int 0x13 I wrote this code to copy kernel code from disk. This code

x86 assembly extreme novice inquiry: “invalid instruction operands”?

岁酱吖の 提交于 2020-11-29 10:09:03
问题 The code below is only a small fraction of the program I am currently attempting to write, but no other parts of the program are relevant, so I only pasted what was necessary. Anyway, what I am trying to do is move the value stored within inputLoopCounter into ecx in order to determine how many times a loop should execute. However, when I attempt to assemble this program, I get the error mentioned in the question title. Can anybody explain the reason for this? .data inputLoopCounter BYTE -1

x86 assembly extreme novice inquiry: “invalid instruction operands”?

…衆ロ難τιáo~ 提交于 2020-11-29 10:08:44
问题 The code below is only a small fraction of the program I am currently attempting to write, but no other parts of the program are relevant, so I only pasted what was necessary. Anyway, what I am trying to do is move the value stored within inputLoopCounter into ecx in order to determine how many times a loop should execute. However, when I attempt to assemble this program, I get the error mentioned in the question title. Can anybody explain the reason for this? .data inputLoopCounter BYTE -1

difference of 'INT' instruction between Linux and Windows

独自空忆成欢 提交于 2020-11-29 10:07:06
问题 I write some code to make my own operating system and study x86 assembly language, too. While studying x86 assembly language, I start wondering about interrupt. Look at below assembly code: mov ah, 2 mov dl, 'A' int 0x21 This code prints 'A' to the screen. it is for MS-DOS. mov eax, 1 mov ebx, 0 int 0x80 This code makes program to exit. it is for Linux. The last one: mov ah, 2 mov al, 1 mov ch, 0 mov cl, 2 mov dh, 0 mov dl, 0 int 0x13 I wrote this code to copy kernel code from disk. This code

MASM: How to resolve Immediate mode Illegal in 8086 programming?

|▌冷眼眸甩不掉的悲伤 提交于 2020-11-29 10:00:47
问题 I am solving a fundamental question of Assembly Language Programming to add BCD numbers and two ASCII numbers, for that I got that I have to use DAA and AAA instructions respectively, Now I am trying to store the result stored in AX register into my desirable memory location, but not getting that why the following code is giving me error Immediate mode Illegal Below is the code that I have coded till now, please help me that how to eradicate this error PS: I want to move my result into my

Can't compile asm hello world with gcc

纵然是瞬间 提交于 2020-11-29 09:45:31
问题 This is the code in hello.s .data hello_str: .string "Hello, world!\n" .set hello_str_length, . - hello_str - 1 .text .globl main .type main, @function main: movl $4, %eax movl $1, %ebx movl $hello_str, %ecx movl $hello_str_length, %edx int $0x80 movl $1, %eax movl $0, %ebx int $0x80 .size main, . - main I run gcc hello.s -o hello and get this error: /usr/bin/ld: /tmp/cc6ILJpd.o: relocation R_X86_64_32 against '.data' can not be used when making a shared object; recompile with -fPIC /usr/bin