;============================================================================== ;file :encode2.asm ;author :Andre Long ;due :March 15, 2006 ;description :This program will encode 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 a decimal number no greater than 128 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 = ", '$' messOct DB "encoded data Octal format = ", '$' inputNumber DW ? inputParity DW ? parityBits DW 0 dataFormat DW 0 holdP1 DW 0000000101010101B holdP2 DW 0000000100110011B holdP4 DW 0000000001110000B holdP8 DW 0000000000000111B p1 DW 0 p2 DW 0 p4 DW 0 p8 DW 0 ;============================================================================== .CODE encode proc _Begin sPutStr getInput call GETDEC$ mov inputNumber,ax sPutStr outPut2 mov bl, 1 call PUTBIN call NEWLINE formatData: mov ax,inputNumber and ax,0000000001000000B shl ax, 2 or dataFormat,ax mov ax,inputNumber and ax,0000000000111000B shl ax, 1 or dataFormat,ax mov ax,inputNumber and ax, 0000000000000111B or dataformat, ax sPutStr formatD mov ax, dataFormat call PUTBIN push dataFormat dataEncode: 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, 10000000000B or dataFormat, cx ;flip p1 from zero to one Par2: mov dx, dataFormat and dx, holdP2 mov inputParity,dx 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, 01000000000B or dataFormat, cx Par4: mov dx, dataFormat and dx, holdP4 mov inputParity,dx 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, 00010000000B 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 continue nOdd8: pop dataFormat mov cx, 00000001000B or dataFormat, cx continue: mov ax, dataFormat call NEWLINE sPutStr messEncode call PUTBIN call NEWLINE sPutStr messOct mov bl, 1 call PUTOCT _Exit encode endp end encode