Learning Assembly in Linux

Thread Solved

Join Date: Dec 2008
Posts: 25
Reputation: jt_murphree is an unknown quantity at this point 
Solved Threads: 1
jt_murphree's Avatar
jt_murphree jt_murphree is offline Offline
Light Poster

Learning Assembly in Linux

 
0
  #1
Dec 9th, 2008
Hello all. This past semester I took assembly programming. The programs in class were done on windwos machines and now I am trying to write some assembly on my linux machine, which has an intel 64bit processor. I am having a problem converting integers to ascii for output. I am using the same routine we used in my class which adds 30h to each digit and store it in a string but I am not getting the approptiate output. The number I am trying to output is 15 but I get D and a small black circle with a white question mark insid it. Does anyone know what is causing this? Is it an issue with using 64bit processor or is it an encoding issue in linux?
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Learning Assembly in Linux

 
0
  #2
Dec 9th, 2008
I'd guess your code.

Get better information by posting your actual code.
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 16,144
Reputation: jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all 
Solved Threads: 530
Moderator
Featured Poster
jbennet's Avatar
jbennet jbennet is offline Offline
Moderator

Re: Learning Assembly in Linux

 
0
  #3
Dec 9th, 2008
an intel 64bit processor
Do you mean an actual 64 bit CPU? Like an Itanium? Or do you mean a normal x86 CPU with the EMT64 extensions?
Last edited by jbennet; Dec 9th, 2008 at 1:27 pm.
If i am helpful, please give me reputation points.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 25
Reputation: jt_murphree is an unknown quantity at this point 
Solved Threads: 1
jt_murphree's Avatar
jt_murphree jt_murphree is offline Offline
Light Poster

Re: Learning Assembly in Linux

 
0
  #4
Dec 9th, 2008
it is a core 2 duo so if I remember correctly it has the 64 extensions. As for the code I will have to post it tonight. I do not have it with me right now.
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 16,144
Reputation: jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all 
Solved Threads: 530
Moderator
Featured Poster
jbennet's Avatar
jbennet jbennet is offline Offline
Moderator

Re: Learning Assembly in Linux

 
0
  #5
Dec 9th, 2008
Yeah the Core2 has the EMT64 extensions
If i am helpful, please give me reputation points.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 25
Reputation: jt_murphree is an unknown quantity at this point 
Solved Threads: 1
jt_murphree's Avatar
jt_murphree jt_murphree is offline Offline
Light Poster

Re: Learning Assembly in Linux

 
0
  #6
Dec 9th, 2008
Here is the code I have written. All I am trying to do at this point is add two numbers and convert the result to ascci and print to screen.
  1. section .data
  2.  
  3. msg db 'Hello, world! this is jason.',0xa ;our dear string
  4. len equ $ - msg ;length of our dear string
  5. MAXSTR equ 256d
  6.  
  7. section .bss
  8. num1: resd 1
  9. num2: resd 1
  10. resultSt: resb MAXSTR
  11. strAddr: resd 1
  12. strLen: resd 1
  13. section .text
  14. global _start ;must be declared for linker (ld)
  15.  
  16. _start: ;tell linker entry point
  17.  
  18. mov eax, 5d
  19. mov ebx, 10d
  20. add eax, ebx
  21. mov dword [num1], eax
  22.  
  23. lea esi, [num1]
  24. lea edi, [resultSt]
  25. call int2ascii
  26.  
  27. lea esi, [resultSt]
  28. call printString
  29.  
  30. ;mov edx,len ;message length
  31. ;mov ecx,msg ;message to write
  32. ;mov ebx,1 ;file descriptor (stdout)
  33. ;mov eax,4 ;system call number (sys_write)
  34. ;int 0x80 ;call kernel
  35.  
  36. mov eax,1 ;system call number (sys_exit)
  37. int 0x80 ;call kernel
  38.  
  39. ;********************procedure to convert int to ascii********************
  40. ;integer to be converted in esi, destination string in edi
  41. ;*************************************************************************
  42. int2ascii:
  43. pushad ;push registers
  44. pushfd ;push flags
  45. cld ;clear direction flag
  46.  
  47. mov eax, [esi] ;load number to eax
  48. mov ecx, 0h ;zero ecx for digit counter
  49. mov ebx, 10d ;move divisor of 10 to ebx
  50. nextOut:
  51. mov edx, 0h ;zero edx for high order word of division
  52. div ebx ;divide by 10
  53. push edx ;push the remainder
  54. inc ecx ;count digit
  55. cmp eax, 0h ;compare eax to 0
  56. jg nextOut ;if greater jump to nextOut
  57.  
  58. charOut:
  59. pop eax ;get number from stack
  60. or eax, 0030h ;or with 30h to get int
  61. stosb ;store in destination string
  62. dec ecx ;decrease chars to print by one
  63. jnz charOut ;if CX > 0 go to charOut
  64. mov al, 0d ;mov 0 to al
  65. stosb ;terminate string
  66. popfd ;restore registers and flags
  67. popad
  68. ret
  69.  
  70. ;***************************printString procedure**********************
  71. ;Given : string to print in esi
  72. ;process : print string using linux sys_call to print to screen
  73. ; no registers or flags are affected
  74. ;returns : nothing
  75. ;**********************************************************************
  76. printString:
  77. pushad ;save flags and registers
  78. pushfd
  79. cld ;clear direction flag to print forward
  80. mov dword [strAddr], esi ;save string address
  81. mov dword [strLen], 0 ;set length to 0
  82.  
  83. whileChar:
  84. cmp BYTE [esi], 0 ;compare string element to 0
  85. jz endWhileChar ;if zero end loop
  86. inc dword [strLen] ;increment string length
  87. inc esi ;increment esi
  88. jmp whileChar ;jump to start of loop
  89.  
  90. endWhileChar:
  91. mov edx, strLen
  92. mov ecx, strAddr ;string address
  93. mov ebx, 1 ;stdout
  94. mov eax, 4 ;syscall numbedr for write
  95. int 0x80 ;call system
  96.  
  97. popfd ;restore flags and registers
  98. popad
  99. ret ;return to calling procedures
Last edited by Narue; Dec 10th, 2008 at 9:01 am. Reason: added code tags
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 25
Reputation: jt_murphree is an unknown quantity at this point 
Solved Threads: 1
jt_murphree's Avatar
jt_murphree jt_murphree is offline Offline
Light Poster

Re: Learning Assembly in Linux

 
0
  #7
Dec 9th, 2008
well I found one problem. I have to put the size for the variable in the print routine before making the syscall to write.
mov edx, dword [strLen]
mov ecx, dword [strAddr]

However, now I am getting no output after converting the number to a string. I am using nasm by the way.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 25
Reputation: jt_murphree is an unknown quantity at this point 
Solved Threads: 1
jt_murphree's Avatar
jt_murphree jt_murphree is offline Offline
Light Poster

Re: Learning Assembly in Linux

 
0
  #8
Dec 10th, 2008
ok I made one of those boneheaded mistakes. I made the changes mentioned in my last post and I was getting no output. I looked at the code for thirty minutes before noticing that I had commented out the call to the conversion procedure. Everything is working as it should noe. Thanks for all your help.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Assembly Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC