;============================================================================== ;file :decode.asm ;author :Andre Long ;due :March 20, 2006 ;description :This program will decode 7 bit data values, using the"parity" ; subprocedure to count the number of bits set to 1 ;============================================================================== ;Procedures To INCLUDE Pcmac.inc ;macros EXTRN NEWLINE:FAR ;display a new line EXTRN PUTBIN:FAR ;display binary number EXTRN GETDEC$:FAR ;gets 16-bit decimal number EXTRN PUTDEC$:FAR ;display 16-bit decimal number EXTRN PUTOCT:FAR ;display 16-bit octal number EXTRN PUTSTRNG:FAR ;display a string EXTRN parity:FAR ;count number of ones ;============================================================================== .MODEL SMALL .586 .STACK 100h ;============================================================================== .DATA PUBLIC inputNumber PUBLIC inputParity PUBLIC parityBits getInput DB "Enter the encoded value: ",'$' outPut1 DB "Number of bits set to 1 = ", '$' outPut2 DB "Binary format of entered number is: ", '$' receptionA DB "Recieved data is good!", '$' receptionB DB "Bad data bit is: ", '$' formatD DB "formatted data = ", '$' messDecodeD DB "decoded data decimal = ", '$' messdecodeQ DB " decoded data octal = ", '$' messOct DB "decoded data Octal format = ", '$' inputNumber DW ? inputParity DW ? parityBits DW 0 dataFormat DW 0 holdP1 DW 0000000101010101B holdP2 DW 0000000100110011B holdP4 DW 0000000001110000B holdP8 DW 0000000000001111B p1 DW 0 p2 DW 0 p4 DW 0 p8 DW 0 storeP1 DW ? storeP2 DW ? storeP4 DW ? storeP8 DW ? storePbits DW 0 mmask DW 0000100000000000B messRepairD DB "Repaired Data Decimal: ", '$' messRepairB DB "Repaired Data Binary: ", '$' messRepairQ DB "Repaired Data Octal: ", '$' cargo DW ? dp1 DW 0 dp2 DW 0 dp3 DW 0 ;============================================================================== .CODE decode proc _Begin sPutStr getInput call GETDEC$ mov dataFormat, ax and ax, holdP1 mov inputParity, ax call parity mov bx, parityBits mov p1, bx mov ax, p1 ntest1: mov bx, 2 mov dx, 0 div bx ;Ax = Dx:Ax / bx cmp dx, 0 ;dx stores the remainder je nEven1 jmp nOdd1 nEven1: mov storeP1, 0000000000000000B jmp Par2 nOdd1: mov storeP1, 0000000000000001B jmp Par2 Par2: mov ax, dataFormat and ax, holdP2 mov inputParity, ax call parity mov bx, parityBits mov p2, bx mov ax, p2 ntest2: mov bx, 2 mov dx, 0 div bx ;Ax = Dx:Ax / bx cmp dx, 0 ;dx stores the remainder je nEven2 jmp nOdd2 nEven2: mov storeP2, 0000000000000000B jmp Par4 nOdd2: mov storeP2, 0000000000000001B jmp Par4 Par4: mov ax, dataFormat and ax, holdP4 mov inputParity, ax call parity mov bx, parityBits mov p4, bx mov ax, p4 ntest4: mov bx, 2 mov dx, 0 div bx ;Ax = Dx:Ax / bx cmp dx, 0 ;dx stores the remainder je nEven4 jmp nOdd4 nEven4: mov storeP4, 0000000000000000B jmp Par8 nOdd4: mov storeP4, 0000000000000001B jmp Par8 Par8: mov ax, dataFormat and ax, holdP8 mov inputParity, ax call parity mov bx, parityBits mov p8, bx mov ax, p8 ntest8: mov bx, 2 mov dx, 0 div bx ;Ax = Dx:Ax / bx cmp dx, 0 ;dx stores the remainder je nEven8 jmp nOdd8 nEven8: mov storeP8, 0000000000000000B jmp red nOdd8: mov storeP8, 0000000000000001B jmp red red: mov bx, 0 or bx, storeP8 shl bx, 1 or bx, storeP4 shl bx, 1 or bx, storeP2 shl bx, 1 or bx, storeP1 cmp bx, 0 jnz ptB jmp ptA ptA: sPutStr receptionA jmp ptC ptB: sPutStr receptionB mov ax,bx mov cx, bx call putdec$ mov dx, mmask ;start of the repair process shr dx, cl mov ax, dataFormat xor ax, dx mov dataFormat, ax call newline sPutStr messRepairD call putdec$ call newline sPutStr messRepairB call putbin call newline sPutStr messRepairQ mov bl, 1 call putoct jmp ptC ptC: mov ax, dataFormat and ax, 0000000000000111B mov dp1, ax mov ax, dataFormat and ax, 0000000001110000B shr ax, 1 mov dp2, ax mov ax, dataFormat and ax, 0000000100000000B shr ax, 2 add ax, dp1 add ax, dp2 call newline sPutStr messDecodeD call putdec$ sPutStr messDecodeQ mov bl, 1 call putoct _Exit decode endp end decode