Asm Source - Hamm Encoding

This is a simple little assembly program for Hamm Encoding.

;///////////////////////////////////////
;/// \file main.asm
;/// \brief Main program for Hamm's encoding project in CISP310
;///
;/// \author John 'Ghost' Wicks
;/// \version 00.99.00
;/// \date October 16, 2007
;///
;//////////////////////// 
;// History 
;// INI 2007-10-16 v00.99.00 Initial release 
  PAGE    80,132
  .MODEL  SMALL,BASIC
  .586

  EXTRN   CLEAR:FAR           ;Clear Screen utility
  EXTRN   PUTSTRNG:FAR    ;Displays a string on the screen
  EXTRN  PUTDEC$:FAR
  EXTRN  GETDEC$:FAR
  EXTRN  PUTBIN:FAR
  EXTRN  NEWLINE:FAR
  EXTRN   BLANKS:FAR
  EXTRN  GETPARITY:FAR      ;Parity Checking Routine
  
DG1_MASK  EQU  0000000000000111b  ;Bit Mask for first three bits in data
DG2_MASK  EQU  0000000000111000b  ;Bit Mask for second three bits in data
DG3_MASK  EQU 0000000001000000b  ;Bit Mask for last bit in data
PG1_MASK  EQU 0000000000001111b
PG2_MASK  EQU  0000000011110000b
PG3_MASK  EQU 0000001100110011b
PG4_MASK  EQU 0000010101010101b
  
  .STACK 256h

  .DATA
programName  DB  'Hamming Encoding Checking Program'
versionName  DB  ' - v 0.99.00',13,10
copyright  DB  'Copyright (c) 2007 John William Wicks',13,10,13,10
prompt    DB  'Enter a number to encode: '
sOrig    DB  'Original Value: '
sEncoded  DB  'Encoded Value:  '
number    DW  0
count    DW  0
dg1      DW  0
dg2      DW  0
dg3      DW  0
pg1      DW  0
pg2      DW  0
pg3      DW  0
pg4      DW  0
encVal    DW  0

  .CODE
        ASSUME  CS:@CODE,DS:NOTHING,ES:@DATA,SS:@STACK
main   PROC
        mov ax, seg @data
        mov es, ax
        mov ds, ax
        call clear
        call ShowCopyright
    call GetNumber

    lea di, sOrig
    mov cx, 16
    call putstrng    
    mov ax, number
    mov bl, -1
    call putbin
    mov dx, 2
    call blanks
    mov bh, -1
    call putdec$
    call newline
    
    push number
    call CalcDataGroups
    call CalcEncodeVal

    lea di, sEncoded
    mov cx, 16
    call putstrng    
    mov ax, encVal
    mov bl, -1
    call putbin
    mov dx, 2
    call blanks
    mov bh, -1
    call putdec$
    call newline
    
        mov al, 0 
        mov ah, 4ch
        int 21h
main   ENDP

ShowCopyright PROC NEAR PUBLIC USES CX DI
        lea di, programName
        mov cx, 30
        call putstrng
    lea di, versionName
        mov cx, 14
        call putstrng
    lea di, copyright
        mov cx, 41
        call putstrng
    ret
ShowCopyright ENDP

GetNumber PROC NEAR PUBLIC USES AX CX DI
    lea di, prompt
     mov cx, 26  
      call putstrng
    call getdec$
    mov number,ax    ;Store the number
    ret
GetNumber ENDP

CalcDataGroups PROC NEAR PUBLIC USES AX BX,
  VAL:WORD
    mov ax, VAL
    and ax, DG1_MASK
    mov dg1, ax
    mov ax, VAL
    and ax, DG2_MASK
    mov dg2, ax
    shl dg2, 1
    mov ax, VAL
    and ax, DG3_MASK
    mov dg3, ax
    shl dg3, 2
    ret
CalcDataGroups ENDP

CalcEncodeVal PROC NEAR PUBLIC USES AX DX
    mov ax, dg1
    or encVal, ax

    mov ax, dg2
    or encVal, ax

    mov ax, dg3
    or encVal, ax

    call CalcParityGroups

    push pg1
    call GetParity

    and ax, 01b
    shl ax, 3
    or encVal, ax
          
    push pg2
    call GetParity

    and ax, 01b
    shl ax, 7
    or encVal, ax

    push pg3
    call GetParity

    and ax, 01b
    shl ax, 9
    or encVal, ax

    push pg4
    call GetParity

    and ax, 01b
    shl ax, 10
    or encVal, ax
          
    ret
CalcEncodeVal ENDP

CalcParityGroups PROC NEAR PUBLIC USES AX DX
    mov ax, encVal
    and ax, PG1_MASK
    mov pg1, ax
    mov ax, encVal
    and ax, PG2_MASK
    mov pg2, ax
    mov ax, encVal
    and ax, PG3_MASK
    mov pg3, ax
    mov ax, encVal
    and ax, PG4_MASK
    mov pg4, ax                    
    ret
CalcParityGroups ENDP

  END main


Written by John Wicks.