;============================================================================== ;file :encode.asm ;author :Andre Long ;due :March 15, 2006 ;description :This program will encode 16 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 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 a decimal number no greater than 2047 unsigned: ",'$' outPut1 DB "Number of bits set to 1 = ", '$' outPut2 DB "Binary format of entered number is: ", '$' formatD DB "formatted data = ", '$' messEncode DB "encoded data = ", '$' inputNumber DW ? inputParity DW ? parityBits DW 0 dataFormat DW 0 holdP1 DW 0010101010101010B holdP2 DW 0010011001100110B holdP4 DW 0000111000011110B holdP8 DW 0000000011111110B holdP16 DW 0000000000000000B p1 DW 0 p2 DW 0 p4 DW 0 p8 DW 0 p16 DW 0 messTest DB "p2 =", '$' messParity DB "Parity Bits = ", '$' messIn DB "inputParity = ", '$' ;============================================================================== .CODE encode proc _Begin sPutStr getInput call GETDEC$ sPutStr outPut2 mov bl, 1 call PUTBIN mov inputNumber,ax call NEWLINE formatData: and ax, 0000010000000000B shl ax, 3 ;bit 6 or dataFormat, ax mov ax, inputNumber and ax, 0000001000000000B shl ax, 2 ;bit 7 or dataFormat, ax mov ax, inputNumber and ax, 0000000100000000B shl ax, 2 ;bit 8 or dataFormat, ax mov ax, inputNumber and ax, 0000000010000000B shl ax, 2 ;bit 9 or dataFormat, ax mov ax, inputNumber and ax, 0000000001000000B shl ax, 1 ;bit 10 or dataFormat, ax mov ax, inputNumber and ax, 0000000000100000B shl ax, 1 ;bit 11 or dataFormat, ax mov ax, inputNumber and ax, 0000000000010000B shl ax, 1 ;bit 12 or dataFormat, ax mov ax, inputNumber and ax, 0000000000001000B shl ax, 1 ;bit 13 or dataFormat, ax mov ax, inputNumber and ax, 0000000000000100B shl ax, 1 ;bit 14 or dataFormat, ax mov ax, inputNumber and ax, 0000000000000010B shl ax, 1 ;bit 15 or dataFormat, ax mov ax, inputNumber and ax, 0000000000000001B shl ax, 1 ;bit 16 or dataFormat, ax sPutStr formatD mov ax, dataFormat call PUTBIN push dataFormat mov dx, dataFormat and dx, holdP1 mov inputParity,dx call parity mov ax, parityBits push dataFormat 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 p1, 0000000000000000B jmp Par2 nOdd1: pop dataFormat mov cx, 1000000000000000B or dataFormat, cx ;flip p1 from zero to one Par2: mov dx, dataFormat and dx, holdP2 mov inputParity,dx mov ax, inputParity call parity mov ax, parityBits push dataFormat jmp ntest2 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 p2, 0000000000000000B jmp Par4 nOdd2: pop dataFormat mov cx, 0100000000000000B or dataFormat, cx Par4: mov dx, dataFormat and dx, holdP4 mov inputParity,dx mov ax, inputParity call parity mov ax, parityBits push dataFormat jmp ntest4 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 p4, 0000000000000000B jmp Par8 nOdd4: pop dataFormat mov cx, 0001000000000000B or dataFormat, cx Par8: mov dx, dataFormat and dx, holdP8 mov inputParity,dx call parity mov ax, parityBits push dataFormat jmp ntest8 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 p8, 0000000000000000B jmp Par16 nOdd8: pop dataFormat mov cx, 0000000100000000B or dataFormat, cx Par16: mov dx, dataFormat and dx, holdP16 mov inputParity,dx call parity mov ax, parityBits push dataFormat jmp ntest16 ntest16: mov bx, 2 mov dx, 0 div bx ;Ax = Dx:Ax / bx cmp dx, 0 ;dx stores the remainder je nEven16 jmp nOdd16 nEven16: mov p16, 0000000000000000B jmp continue nOdd16: pop dataFormat mov cx, 0000000000000000B or dataFormat, cx continue: mov ax, dataFormat call NEWLINE sPutStr messEncode call PUTBIN _Exit encode endp end encode