Advertisement

04.26.2005 at 06:45PM PDT, ID: 21403665
[x]
Attachment Details

Assembly Program to convert to any base

Asked by jer2eydevil88 in Assembly Programming Language

Tags: base, convert, assembly, any, program

I'm trying to write an assembly program that will take two integer inputs. One must be a number to be converted and one must be the base to convert to. Right now my program is hanging up after one input. My code is posted below and I tried to comment it the best i could. If someone could edit it to do what it needs to do, that would help a lot!

.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 THIS ALSO NEEDS TO CHANGES FOR DIFFERENT BASES!!!
                  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
                  Start Free Trial
 
Loading Advertisement...
 
[+][-]04.28.2005 at 12:58PM PDT, ID: 13889461

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Assembly Programming Language
Tags: base, convert, assembly, any, program
Sign Up Now!
Solution Provided By: Dawaffleman
Participating Experts: 3
Solution Grade: A
 
 
[+][-]04.30.2005 at 04:14AM PDT, ID: 13900314

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.13.2006 at 07:51PM PST, ID: 15948007

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.17.2006 at 03:35AM PST, ID: 15979604

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32