2 Replies - 6744 Views - Last Post: 28 March 2010 - 07:28 AM

#1 nathanpc   User is offline

  • SCIENCE!
  • member icon

Reputation: 113
  • View blog
  • Posts: 1,171
  • Joined: 31-July 09

Convert ASCII To Binary

Posted 03 December 2009 - 05:19 AM

Description: For this you will need Fasm and emu8086. - Fasm: http://flatassembler.net/download.php - emu8086: http://www.emu8086.com/ASCII converter to binary using Fasm syntax
#make_COM#

; COM file is loaded at CS:0100h
org 10h

; ********************************
; *    Program: ASCIICONV.ASM    *
; ********************************

include 'emu8086.inc'
.model small
.stack 512d

.data
   size equ 2d
   buffer db size dup ('x')
   
.code
   entry:						; Do the character entry
      print 'Enter a ASCII character: '
      lea di, buffer
      mov dx, size
      call GET_STRING
      putc 13d
      putc 10d
      
      print 'The ASCII code of the character ['
      mov si, di
      call PRINT_STRING
      print '] in binary is equivalent of: '
      
      mov ax, [di]
      mov ah, 10000000b			; mask for a binary value test
      mov cx, 08h				; definition of the 8 bits counter
      write_bit:				; Routine of the binary value presentation
         test al, ah			; verify if the AL interrupt didn't have been modified
         jz write_0				; if the bit test be 0, write it as 0
         putc '1'				; if not, write 1
         jmp next_bit			; get the next bit of the sequence
         write_0:
            putc '0'			; write zero
         next_bit:
         shr ah, 01h			; move one bit from the mask to the right
      loop write_bit
      
      putc 13d
      putc 10d
      print 'Want to finish the execution (Y/N): '
      lea di, buffer
      mov dx, size
      call GET_STRING
      putc 13d
      putc 10d
      mov ax, [di]
      
      cmp ax, 079h				; If the character entered was 'y'
      je get_capital			; convert it to 'Y'
      jne get_normal			; if not, stay the entered
      get_capital:
         sub ax, 020h
      get_normal:
      cmp ax, 059h				; if the answer be different than 'Y'
      je exit					; exit the program
   jmp entry					; if not, enter the next character
   exit:
      hlt
      
   DEFINE_GET_STRING
   DEFINE_PRINT_STRING
end


Is This A Good Question/Topic? 0
  • +

Replies To: Convert ASCII To Binary

#2 nadmike   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 11-February 10

Re: Convert ASCII To Binary

Posted 11 February 2010 - 09:19 PM

how could i do it in 8086 assembly?
Was This Post Helpful? 0
  • +
  • -

#3 nathanpc   User is offline

  • SCIENCE!
  • member icon

Reputation: 113
  • View blog
  • Posts: 1,171
  • Joined: 31-July 09

Re: Convert ASCII To Binary

Posted 28 March 2010 - 07:28 AM

It's already in 8086 Assembly, but as on the instructions, you need to compile it using Fasm, by this command: > fasm asciiconv.asm
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1