User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Assembly section within the Software Development category of DaniWeb, a massive community of 391,596 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,656 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Assembly advertiser:
Views: 553 | Replies: 0
Reply
Join Date: May 2008
Posts: 1
Reputation: R&R is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
R&R R&R is offline Offline
Newbie Poster

Assembly Program to convert to any base

  #1  
May 4th, 2008
Can you tell me what needs to be changed in the program in order to run? Thank you.
.model small
.386
.stack 100h
.data
.code


decimal                  proc            near

;print out number given in AX in decimal

                  xor            eax,eax
                  xor            ebx,ebx
                  mov            cx,2            ;this is to accept the base and the decimal value
                  
newchar:            
                  cmp            cx,0
                  jle            startConvert
                  dec            cx
                  mov            ah,1            ;This sets up to accept another input from keyboard
                  int            21h            ;this asks for an input and stores it in al
                  
                  ;mov            al,0h            ;This sets up to accept another input from keyboard
                  ;int            21h            ;this asks for an input and stores it in al
                  ;push            ax            ;stores the second input from keyboard
                  
                  
                  
                  sub            al,30h
                  jl            stloop            ;jumps if negative
                  cmp            al,9h
                  jg            stloop            ;jumps if greater than
                  
                  xor            ah,ah            ;to get only the digit they type
                  push            ax            ;this stores the first input from the keyboard
                  
                  cbw                        ;convert byte to word
                  ;jmp            newchar            ;to accept multiple digits

stloop:                  
                  mov            ah,2
                  mov            dl,0ah
                  int            21h            ;This section inserts a carrige return
                  mov            dl,0dh
                  int            21h
                  
                  
startConvert:            pop            bx
                  push            ax            ;given to routine to print out
                  ;push            bx
                  push            cx
                  push            dx
                  
                  mov            cx,0            ;starts a counter for the number of digits
                  ;mov            bx,10            ;base 10 conversion THIS IS THE LINE TO CHANGE FOR DIFFERENT BASES!!!!
                  
nonzero:            
                  xor            dx,dx            ;same as mov dx,0
                  div            bx
                  push            dx            ;this is the remainder of the divider
                  inc            cx            ;this will help determine the number of digits produced
                  or            ax,ax            ;sets flags to check is ax = 0
                  jne            nonzero            ;jump not equal to

write:                  
                  pop            dx            ;gets deciaml digit from stack
                  add            dl,'0'      ;ascii value of 30h (what are the values for octal and binary)
                  mov            ah,2
                  int            21h
                  loop            write            ;loops number of times in cx, which is the number of digits
                  pop            dx
                  pop            cx
                  pop            bx
                  pop            ax
                  ret
decimal                  endp
                  end decimal
Last edited by Narue : May 5th, 2008 at 1:43 pm. Reason: Fixed tags
AddThis Social Bookmark Button
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb Assembly Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the Assembly Forum

All times are GMT -4. The time now is 11:43 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC