;============================================================================================================================================= ; ordin.asm ;This program is designed to calculate the ascii difference between 2 letters ; Algorithm ;D1: Get the letter ;D2: Get the second one ;D3: Calculate and show the difference ;D4: Show signature and exit ;(C)I don't take any responsibility for the use of this program ; Zedr0n -- connection closed ;============================================================================================================================================= ;============================================================================================================================================= ; Macros ;============================================================================================================================================= crlf macro mov ah,02h mov dl,0Dh int 21h mov dl,0Ah int 21h endm print macro message mov ah,09h mov dx,offset &message& int 21h endm readsym macro data mov ah,01h int 21h mov byte ptr &data&,al endm ;============================================================================================================================================ ; .Com declaration ;============================================================================================================================================ .model tiny .data signature db 0Dh,0Ah,0Dh,0Ah,0Dh,0Ah,0Dh,0Ah,0Dh,0Ah,0Dh,0Ah,0Dh,0Ah,0Dh,0Ah,0Dh,0Ah,0Dh,0Ah,0Dh,0Ah,0Dh,0Ah, db " --------------------------------- ",0Dh,0Ah, db " \ Zedr0n - connection closed / ",0Dh,0Ah, db " \ 02.11.2001 / ",0Dh,0Ah, db " ----------------------------- ",0Dh,0Ah, db 0Dh,0Ah,0Dh,0Ah,0Dh,0Ah,0Dh,0Ah,0Dh,0Ah,0Dh,0Ah,0Dh,0Ah,0Dh,0Ah, db '$' welcome1 db "Enter the first letter: $" welcome2 db "Enter the second letter: $" result db "The difference is $" First db ? Second db ? .code .386 org 100h start: ;============================================================================================================================================ ; Code segment ;============================================================================================================================================ D1: print welcome1 readsym First crlf D2: print welcome2 readsym Second crlf D3: xor eax,eax xor ebx,ebx xor edx,edx mov al,First mov bl,Second sub al,bl call hexdec call output xor ah,ah int 16h D4: mov ah,9h mov dx,offset signature int 21h ret ;============================================================================================================================================= ; Procedures ;============================================================================================================================================= ;============================================================================================================================================= ; Convert hexadecimal in eax to decimal in edx ;============================================================================================================================================= hexdec proc mov edx,eax mov esi,offset divtab ;pointer subtract values mov edi,offset numbuff ;output buffer mov cx,10 ;5 digits sublop: xor al,al ;clear counter sblop: cmp edx,[esi] ;number < subractor ? jb tolow ;yeah sub edx,[esi] ;noo, subtract add al,1 ;incrase times subtracted jmp sblop ;subtract again tolow: add al,30h ;make ascii stosb ;store in buffer add esi,4 ;next subtractor loop sublop ;do it mov al,0 ;null terminate buffer stosb mov esi,offset numbuff ret divtab: ;subractor values dd 1000000000 dd 100000000 dd 10000000 dd 1000000 dd 100000 dd 10000 dd 1000 dd 100 dd 10 dd 1 numbuff db 34 dup(0) ;number buffer hexdec endp ;============================================================================================================================================= ; Outputs buffer with ascii, where si points to buffer ;============================================================================================================================================= output proc strip: lodsb ;load byte cmp al,'0' ;any leading zeroes ? jne nozero ;noo jmp strip ;yeahh, check next nozero: dec esi ;adjust that back one byte lodsb out: mov dl,al mov ah,02h int 21h lodsb cmp al,0 jnz out ret output endp ;============================================================================================================================================= ; Macros ;============================================================================================================================================= print macro message mov ah,09h mov dx,offset &message& int 21h endm crlf macro mov ah,02h mov dl,0Dh int 21h mov dl,0Ah int 21h endm end start