The Geek Forum

  • April 27, 2024, 03:54:30 AM
  • Welcome, Guest
Please login or register.

Login with username, password and session length
Advanced search  

News:

Due to the prolific nature of these forums, poster aggression is advised.

*

Recent Forum Posts

Shout Box

Members
Stats
  • Total Posts: 129551
  • Total Topics: 7148
  • Online Today: 143
  • Online Ever: 1013
  • (January 12, 2023, 01:18:11 AM)

Author Topic: Computing - How to insert a Parity Bit  (Read 4551 times)

Gamine123

  • Annoying Newbie
  • *
  • Coolio Points: +0/-2
  • Offline Offline
  • Posts: 1
    • View Profile
Computing - How to insert a Parity Bit
« on: November 11, 2009, 05:49:34 AM »

Hi,

I am a Computer Science fresher and I missed the first 3 weeks of class due to admin problems so I get a bit lost for my assignments...

Anyway I've got this assignment that requires me to write a very simple assembly program on Microvision that will take a 7-bit value (0x59) in R1 and insert an odd parity bit at bit position 4, storing the parity-encoded value in R0.

I know I am supposed to use AddC, EOR and MOV functions but I don't know how to do it.
I am not asking for the answer to this particular problem but could anyone give me a general (simple) explanation of how it's done???

Help!!!

Thanks very much
Logged

Probie

  • Professional Blogger
  • ***
  • Coolio Points: +223/-5
  • Offline Offline
  • Posts: 644
  • The natural nap catalyst
    • View Profile
    • SoggyBlog
Re: Computing - How to insert a Parity Bit
« Reply #1 on: November 11, 2009, 06:14:38 AM »


A general simple explanation sounds like an answer to me. But I don't actually have the answer.
Logged
// ------- Probie ------- //
// ----------------------- //
// --- T3H GEEKERY --- //
// ----------------------- //
www.niccisixx.com - I can put this here, because I'm awesome.

ivan

  • Forum Moderator
  • Hacker
  • *
  • Coolio Points: +499/-50
  • Offline Offline
  • Posts: 4929
  • Not a Mod, nor a Rocker. A Mocker.
    • View Profile
Re: Computing - How to insert a Parity Bit
« Reply #2 on: November 11, 2009, 02:48:24 PM »

Well, you need to examine every bit of your value and count the 1s to determine parity. The easiest way to do that is with a shift or rotate command in a loop. Without a shift or rotate command, you can increment your mask instead. So something like this:

VALUE = the value you are testing
MASK = 1 (starting value of mask is 00000001)
LOOPCOUNTER = 0
PARITY = 1 (starting value of PARITY is odd)

start:
VALUE AND MASK --> RESULT (the result of ANDing the mask and value)
PARITY EXCLUSIVEOR RESULT --> PARITY (toggle PARITY if RESULT is 1)
MASK * 2 --> MASK (Advance masked bit to next position)
LOOPCOUNTER + 1 --> LOOPCOUNTER (increment loop counter)
if LOOPCOUNTER < 8 goto start: (repeat loop 7 times)

There might be more elegant ways of counting bits, like with a shift or rotate command. If you're being graded for elegance, this might not pass muster.

And as for inserting the 4th bit, again, there are probably elegant ways of doing this, but you can brute force it like this:

ORIGINALVALUE AND 00000111 --> RIGHTBITS
ORIGINALVALUE AND 11111000 --> LEFTBITS
LEFTBITS * 0x2 --> LEFTBITS
PARITY * 0x8 --> PARITY

LEFTBITS + PARITY + RIGHTBITS --> FINALRESULT

So here we go:

Value to test 1011001 (0x59)

First loop iteration
1011001 AND 00000001 = 1 (value AND mask)
00000001 XOR 1 = 0 (Toggle parity)
00000001 * 10 = 00000010 (shift mask bit for next iteration)

Second iteration
1011001 AND 00000010 = 0 (value AND mask)
00000000 XOR 0 = 0 (parity not toggled)
00000010 * 10 = 00000100 (shift mask bit for next iteration)

etc.

After 7th iteration, Parity has been toggled for each 1 bit, and
ends up set to 1.

Insertion:

1011001 AND 00000111 = 00000001 (right bits)
1011001 AND 11111000 = 01011000 (left bits)
1 * 1000 = 1000 (parity bit)
01011000 * 10 = 10110000 (shift left bits to the left by one position)
10110000 + 1000 + 00000001 = 10111001 (shifted left bits + parity bit + right bits)

The result is 0xb9



Logged
"I TYPE 120 WORDS PER MINUTE, BUT IT'S IN MY OWN LANGUAGE!"  -Detta

xolik: WHERE IS OBAMA'S GIFT CERTIFICATE?
Demosthenes: Is that from the gifters movement?


Detta: Crappy old shorts and a tank top.  This is how I dress for work. Because my job is to get puked on.
Demosthenes: So is mine.  I work in IT.


bananaskittles: The world is 4chan and God is a troll.

Clear_Runway

  • Wannabe Professional Blogger
  • **
  • Coolio Points: +85/-219
  • Offline Offline
  • Gender: Male
  • Posts: 559
  • Apparently sucks at IRC
    • View Profile
Re: Computing - How to insert a Parity Bit
« Reply #3 on: November 11, 2009, 05:47:43 PM »

...wow. really am bad at programming
Logged
"Scatman, fat man, black and white an brown man, tell me 'bout the color of your soul"
- RIP Scatman John

http://themanicnerd.blogspot.com/

ivan

  • Forum Moderator
  • Hacker
  • *
  • Coolio Points: +499/-50
  • Offline Offline
  • Posts: 4929
  • Not a Mod, nor a Rocker. A Mocker.
    • View Profile
Re: Computing - How to insert a Parity Bit
« Reply #4 on: November 11, 2009, 06:08:27 PM »

...wow. really am bad at programming

I doubt it. Not knowing a language or any specifics about any one system does not make one a bad programmer.

However, if you want to feel like a good programmer, learn a macro assembler language (no matter which one). It's easier than C and makes you feel all hacky inside.

(Oh look! I just used seventeen lines of code to draw a pixel!)


Logged
"I TYPE 120 WORDS PER MINUTE, BUT IT'S IN MY OWN LANGUAGE!"  -Detta

xolik: WHERE IS OBAMA'S GIFT CERTIFICATE?
Demosthenes: Is that from the gifters movement?


Detta: Crappy old shorts and a tank top.  This is how I dress for work. Because my job is to get puked on.
Demosthenes: So is mine.  I work in IT.


bananaskittles: The world is 4chan and God is a troll.

sociald1077

  • Hacker
  • ****
  • Coolio Points: +129/-4
  • Offline Offline
  • Gender: Male
  • Posts: 1184
    • View Profile
Re: Computing - How to insert a Parity Bit
« Reply #5 on: November 12, 2009, 03:34:08 PM »

I liked using Motorola assembly for the time I was in a microcontroller class. I have to admit though that using C to do the same opperations was so much easier.
Logged
"Guns don't kill people! PHYSICS kill people!" - Dick Soloman

xolik

  • King of the Geekery
  • Hacker
  • ****
  • Coolio Points: +541/-25
  • Offline Offline
  • Gender: Male
  • Posts: 5176
  • HAY GUYS
    • View Profile
Re: Computing - How to insert a Parity Bit
« Reply #6 on: November 13, 2009, 10:45:44 AM »

1. Cut a hole in a bit
2. Stick your parity in the bit
3. Have her open the bit
Logged
Barium: What you do if CPR fails.

=-=-=-=-=-=-=-=-=-=-=
[The Fade^C Compound]
-=-=-=-=-=-=-=-=-=-=-

ivan

  • Forum Moderator
  • Hacker
  • *
  • Coolio Points: +499/-50
  • Offline Offline
  • Posts: 4929
  • Not a Mod, nor a Rocker. A Mocker.
    • View Profile
Re: Computing - How to insert a Parity Bit
« Reply #7 on: November 13, 2009, 01:02:22 PM »

I suddenly crave pizza.
Logged
"I TYPE 120 WORDS PER MINUTE, BUT IT'S IN MY OWN LANGUAGE!"  -Detta

xolik: WHERE IS OBAMA'S GIFT CERTIFICATE?
Demosthenes: Is that from the gifters movement?


Detta: Crappy old shorts and a tank top.  This is how I dress for work. Because my job is to get puked on.
Demosthenes: So is mine.  I work in IT.


bananaskittles: The world is 4chan and God is a troll.