Fedora Linux Support Community & Resources Center
  #1  
Old 25th April 2009, 08:11 AM
matt123 Offline
Registered User
 
Join Date: Apr 2009
Posts: 10
Assembly language ? converting ascii to decmial

hello, iam tring to figure out assembly langauge and am having a hard time. I want to write a program purely in assembly that takes in a number in base 10 and converts it to hex octal and binary. Just know how to output to the screen and take in from the keyboard, but once i get the number in I am unable to work with them. i think because they are an ascii string as opposed to integers. trying to convert so i can manipulate them for the conversions to different bases. I may be way off, but am definatley lost and would appreciate any guidance!! Here is the code i have so far, but it does not do waht i want it to:

.section .data
input:
.fill 256 #where i would like to store the converted number, if possible
prompt:
.asciz "Enter a decimal integer:"
prompt_end:
.equ promptlength, prompt_end-prompt

.section .bss
.lcomm number, 40 #number taken in from input, in ascii
.section .text
.globl _start
_start:
nop

######## display prompt string ####################
movl $4,%eax
movl $1,%ebx
movl $prompt,%ecx #string for output
movl $promptlength,%edx
int $0x80

######## get input #################################
movl $3, %eax
movl $0, %ebx
movl $number, %ecx
movl $40, %edx
int $0x80


######## convert from ascii to decmial ##############
# %edi holds current index
# %eax holds number
movl $0, %edi
movl number(,%edi,1),%eax
movl $3, %ecx
loop1:
sub $48, %eax
movl %eax, input
incl %edi
movl number(,%edi, 1), %eax
cmpl %edi, %ecx
jge loop1

########## Output converted number # ###############

movl $4, %eax
movl $1, %ebx
movl $input, %ecx
movl $4, %edx
int $0x80

movl $1,%eax
movl $0,%ebx
int $0x81
~


Thanks!!

Last edited by matt123; 25th April 2009 at 07:56 PM.
Reply With Quote
  #2  
Old 25th April 2009, 07:57 PM
matt123 Offline
Registered User
 
Join Date: Apr 2009
Posts: 10
Any assembly programmers out there?
Reply With Quote
  #3  
Old 26th April 2009, 07:16 PM
jaymann Offline
Registered User
 
Join Date: May 2008
Location: Somewhere in time
Posts: 44
I have not done assem in a while.
Let the compiler help you.
Write your function in c
Code:
// test.c
#include <stdio.h>

int main(void)
{
    int i = 0;

    i++;

    return 0;
}
compile
Code:
gcc -Wall -S  -masm=att -o test.asm test.c
output
Code:
	.file	"test.c"
	.text
.globl main
	.type	main, @function
main:
	leal	4(%esp), %ecx
	andl	$-16, %esp
	pushl	-4(%ecx)
	pushl	%ebp
	movl	%esp, %ebp
	pushl	%ecx
	subl	$16, %esp
	movl	$0, -8(%ebp)
	addl	$1, -8(%ebp)
	movl	$0, %eax
	addl	$16, %esp
	popl	%ecx
	popl	%ebp
	leal	-4(%ecx), %esp
	ret
	.size	main, .-main
	.ident	"GCC: (GNU) 4.3.2 20081105 (Red Hat 4.3.2-7)"
	.section	.note.GNU-stack,"",@progbits
__________________
su -c 'yum remove mono-core'
F10/11, Pent 4 550, 500gb HD, 2gb Ram
Acer Aspire One - FC13 RC3
Reply With Quote
  #4  
Old 27th April 2009, 07:10 AM
matt123 Offline
Registered User
 
Join Date: Apr 2009
Posts: 10
figured out the conversion from acsii to numbers that you can work with mathematically. i will post it here:

######## convert from ascii to decmial ##############
# %edi holds current index
# %eax holds number
movl $0, %edi
movl $0, %ebx
loop1:
xor %eax, %eax #set %eax==0
movb number(,%edi,1), %al #get num for conv
cmp $0xA, %eax #check for nul
je done
sub $48, %al #sub for int
push %eax #save value
movl %ebx, %eax
movl $10, %ecx #multiplier
mul %ecx #multiply current value by 10
pop %ebx #
add %eax, %ebx
incl %edi
jmp loop1
done:
movl %ebx, input
movl %edi, declength


Thanks for the help!
Reply With Quote
Reply

Tags
ascii, assembly, converting, decmial, language

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
learning assembly language on fedora 10 User101 Programming & Packaging 5 7th August 2009 08:48 PM
Assembly x86 Tutorials Flounder Programming & Packaging 3 22nd August 2006 06:53 PM
Anyone know Sparc Assembly? nick.stumpos Programming & Packaging 1 17th March 2006 07:11 AM
Assembly Bonboe Using Fedora 1 17th February 2006 09:21 AM
Assembly in Linux divinity Using Fedora 2 3rd February 2005 05:41 AM


Current GMT-time: 14:53 (Saturday, 25-05-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat