:-( Hi,
I am trying to write a project for my class, and I have got part of it, but I can't figure it out rest of it, so if somebody could help me with this. We do our work on x86 Assembly Language using Linux. Following is the question and also part of the code that I have written. If somebody helps me than I than would really really really really very thankful to that person. I know I should do my work by myself, and I do have tried hard, but I just can't get it and it's due soon, so please if anyone has chance review my code and if anything is wrong than if you could explain and change it for me.
And I apologize for putting this huge message on board, I am really very sorry for this, but I need to get this done as soon as possible.
Thanks,
Ami
:-)
[size=4] QUESTION: [/size]
[blue]Write an assembly language program that prompts the user to enter a hexadecimal value, adds 10 (in decimal) to it, then displays the result in hexadecimal. The main function should:[/blue]
[red]
declare a local [b]char[/b] array (along with any other local variables)
call [b]writeStr[/b] to prompt the user to enter a hexidecimal value
call [b]readStr[/b] to read from the keyboard one character at a time
call [b]hexToInt[/b] to convert the string into an integer
add 10 to the integer
call [b]writeStr[/b] to display the result prompt
call [b]intToHex[/b] to convert the integer into a hexadecimal string
call [b]writeStr[/b] to display the hexadecimal string
call [b]writeStr[/b] to display program end prompt
[italic]Your program must use only single character read and write system calls to read from the keyboard and display on the screen.[/italic]
[/red]
[b]
plus_ten - Executable program (do not submit this file)
plus_ten.s - main function
writeStr.s - Function that writes a C-style string on the standard output
readStr.s - Function that reads one line from the standard input
hexToInt.s - Function that converts a C-style string into an unsigned int
intToHex.s - Function converts an int into a text string that represents the int in hexadecimal[/b]
[b][gray]
Each function must be in its own source file.
All local variables must be created in the function's stack frame.
All parameters are to be passed on the stack.
All integers must be stored in the binary number system, not as ascii text strings.
String prompts (e.g. "Enter a hexadecimal string: ") can be stored in the .data segment.
[/gray][/b]
[purple][b]Part of the codes of files:[/b][/purple]
[green][b]writeStr.s:[/b][/green]
#Stack Frame:
count = -4
basePtr = 0
return = 4
stringAddr = 8
.text
.globl writeStr
writeStr:
pushl %ebp
movl %esp, %ebp
addl $count, %esp
# protects registers that calling function may be using and
# we intend to use them
pushl %ecx
pushl %edx
movl $0, count(%ebp)
movl stringAddr(%ebp), %ecx
whileLoop:
cmpb $0, (%ecx)
je done
pushl $1
pushl stringAddr(%ebp)
pushl $1
call write
addl $12, %esp
incl count(%ebp)
incl %ecx
jmp whileLoop
done:
popl %edx
popl %ecx
movl count(%ebp), %eax
popl %ebp
ret
[green][b]HexToInt.s[/b][/green]
# Stack Frame:
Ptr = -8
value = -4
basePtr = 0
return = 4
strPtr = 8
.text
.globl main
main:
pushl %ebp
movl %esp, %ebp
addl $Ptr, %esp
movl $0, value(%ebp)
movl strPtr(%ebp), %eax
movl %eax, Ptr(%ebp)
whileLoop:
movl ptr(%ebp), %eax
cmpb $0, (%eax)
je done
movl (%eax), %al
andl $0x0f, %eax
shll $4, value(%ebp)
addl %eax, value(%ebp)
incl Ptr(%ebp)
jmp whileLoop
done:
movl value(%ebp), %eax
movl %ebp, %esp
popl %ebp
ret
[green][b]readStr.s[/b][/green]
#Stack Frame:
count = -4
basePtr = 0
return = 4
stringAddr = 8
.text
.globl readStr
readStr:
pushl %ebp
movl %esp, %ebp
addl $count, %esp
pushl %ecx
pushl %edx
movl stringAddr(%ebp), %ecx
whileLoop:
cmpb $0, (%ecx)
je done
pushl $1
pushl stringAddr(%ebp)
pushl $1
call read
addl $12, %esp
incl count(%ebp)
incl %ecx
jmp whileLoop
done:
popl %edx
popl %ecx
movl count(%ebp), %eax
popl %ebp
ret
[green][b]IntToHex.s[/b][/green]
# Stack Frame:
Ptr = -8
value = -4
basePtr = 0
return = 4
strPtr = 8
.text
.globl main
main:
pushl %ebp
movl %esp, %ebp
addl $ptr, %esp
movl $0, value(%ebp)
movl strPtr(%ebp), %eax
movl %eax, ptr(%ebp)
whileLoop:
movl ptr(%ebp), %eax
cmpb $0, (%eax)
je done
movl (%eax), %al
andl $0x0f, %eax
shll $4, value(%ebp)
addl %eax, value(%ebp)
incl ptr(%ebp)
jmp whileLoop
done:
movl value(%ebp), %eax
movl %ebp, %esp
popl %ebp
ret
[red][b]I haven't got to plus_ten.s file yet which is main function that calls writeStr.s, readStr.s, HexToInt.s, and IntToHex.s and also it adds 10 to the applied hexadecimal text string.[/red][/b]
[purple][b]I would really very appreciate that helpful person.[/b][/purple]