Nasm to tasm code help

Reply

Join Date: Mar 2006
Posts: 8
Reputation: deutsch is an unknown quantity at this point 
Solved Threads: 0
deutsch's Avatar
deutsch deutsch is offline Offline
Newbie Poster

Nasm to tasm code help

 
0
  #1
Mar 18th, 2006
Is there someone who could help me convert this
to Tasm style.

Thanks.
  1. ; celsius.asm Nasm code
  2. ; Need this converted to Tasm style
  3. ; so I can help him
  4.  
  5. BITS 16 ;16 bit instructions used
  6. ORG 100h ;start of .com program
  7.  
  8.  
  9. SECTION .text ;text section follows
  10.  
  11.  
  12. main:
  13. mov si,prompt1
  14. call PrintString
  15.  
  16. mov di,Instring
  17. call ReadString
  18. call CRLF ;INPUT Instring$
  19. mov si,Instring
  20. call StrToNum ;ax = VAL(InString$)
  21.  
  22. ; ------- ax = (int)((ax - 32) * 5 / 9) -----------
  23.  
  24. sub ax,32 ;ax = ax - 32
  25. mov bx,5
  26. imul bx ;ax = ax * 5
  27. mov bx,9
  28. idiv bx ;ax = ax / 9 (dx = remainder, ax = quotient)
  29. xchg ax,dx ;now ax = remainder and dx = quotient
  30.  
  31. ; round up the value
  32. mov bl,5
  33. idiv bl ;al = al / bl
  34. cbw ;convert byte to word
  35. add ax,dx ;ax = ax + quotient
  36.  
  37. mov si,Instring
  38. call NumToStr ;InString$ = STRING$(ax)
  39. mov si,Instring
  40. call PrintString
  41. call CRLF ;PRINT InString$
  42.  
  43. ;--------------------------------------------------
  44. mov ax,4C00h
  45. int 21h
  46.  
  47. ;** READ KEYBOARD TO STRING POINTED TO BY DI **
  48. ;** ReadString(SI) **
  49.  
  50. ReadString:
  51. push dx
  52. push ax
  53. push di
  54. push bx
  55. mov bx,di
  56. NextChar:
  57. sub ah,ah
  58. int 16h ;wait for key function
  59. cmp al,13 ;[ENTER] key?
  60. jz Done
  61. cmp al,8 ;[<-] key?
  62. jz BackSpace
  63. mov [di],al ;save character
  64. inc di
  65. mov dl,al ;
  66. mov ah,2
  67. int 21h ;echo character
  68. jmp NextChar
  69.  
  70. BackSpace:
  71. cmp di,bx ;at beginning?
  72. jz NextChar ;yep no back space
  73. dec di
  74. mov ah,2
  75. mov dl,8
  76. int 21h ;backspace
  77. mov ah,2
  78. mov dl,' ';
  79. int 21h ;PRINT " ";
  80. mov ah,2
  81. mov dl,8
  82. int 21h ;backspace
  83. jmp NextChar
  84.  
  85. Done:
  86. sub al,al ;clear al
  87. mov [di],al ;null string
  88. pop bx
  89. pop di
  90. pop ax
  91. pop dx
  92. ret
  93.  
  94. ;** PRINT STRING POINTED TO BY SI **
  95. PrintString:
  96. push dx
  97. push ax
  98. push si
  99. PrintLoop:
  100. mov al,[si]
  101. inc si
  102. or al,al ;test for al=0
  103. jz Finish
  104. mov dl,al
  105. mov ah,2
  106. int 21h ;print character
  107. jmp PrintLoop
  108. Finish:
  109. pop si
  110. pop ax
  111. pop dx
  112. ret
  113.  
  114. CRLF:
  115. push ax
  116. push dx
  117. mov ah,2
  118. mov dl,13
  119. int 21h
  120. mov dl,10 ;lf
  121. int 21h
  122. pop dx
  123. pop ax
  124. ret
  125.  
  126. ;** Convert string pointed to by SI to number in ax **
  127. StrToNum:
  128. push bx
  129. push cx
  130. push dx
  131. push si
  132. mov BYTE [sign],0 ;assume positive number
  133. sub cx,cx ;cx = 0
  134. mov bx,10 ;base 10
  135. mov al,[si]
  136. cmp al,'-'
  137. jne NextDigit ;positive number
  138. inc si ;skip '-' character
  139. mov BYTE [sign],1 ;negative number
  140. NextDigit:
  141. mov al,[si] ;get digit
  142. inc si
  143. sub ah,ah ;ah = 0
  144. sub al,'0' ;convert to 0-9 value
  145. jc NotDecDigit
  146. cmp al,10 ;
  147. ja NotDecDigit
  148. xchg ax,cx ;ax = old value cx = new value
  149. mul bx ;ax = ax * 10
  150. add cx,ax ;add new result
  151. jno NextDigit
  152. call OverFlow
  153. NotDecDigit:
  154. mov ax,cx ;ax = result
  155. cmp dl,BYTE [sign]
  156. jz positive
  157. neg ax ;was negative signed
  158. positive:
  159. pop si
  160. pop dx
  161. pop cx
  162. pop bx
  163. ret
  164.  
  165. OverFlow:
  166. push ax
  167. push bx
  168. push cx
  169. push dx
  170. push si
  171. call CRLF
  172. mov si,error2
  173. call PrintString
  174. call CRLF
  175. pop si
  176. pop dx
  177. pop cx
  178. pop bx
  179. pop ax
  180. ret
  181.  
  182. ;** Convert number in ax to string pointed to by DI **
  183. NumToStr:
  184. push ax
  185. push dx
  186. push cx
  187. push bx
  188. push di
  189. mov bx,10
  190. xor cx,cx
  191. cmp ax,0
  192. jge NotZero ;ax positive number
  193. neg ax ;2's complement
  194. mov BYTE [di],'-'
  195. inc di
  196. NotZero:
  197. xor dx,dx ;set upper word of N to 0
  198. div bx ;N/10 and n mod 10
  199. add dl,'0' ;remainder in dl convert to asc
  200. push dx ;push one digit onto stack
  201. inc cx ;count digits
  202. or ax,ax ;n = 0?
  203. jne NotZero
  204. PopDigit:
  205. pop ax ;last digit first
  206. mov [di],al ;
  207. inc di
  208. loop PopDigit
  209. sub al,al ;al = 0
  210. mov [di],al ;null string
  211. pop di
  212. pop bx
  213. pop cx
  214. pop dx
  215. pop ax
  216. ret
  217.  
  218. WaitKey:
  219. mov ah,7
  220. int 21h
  221. ret
  222.  
  223. section .data
  224.  
  225.  
  226. prompt1 db ' Enter number: ',0
  227.  
  228. error1 db 'overflow',0
  229. error2 db 'input OVERFLOW',0
  230.  
  231. sign db 0 ;sign of number
  232.  
  233. section .bss
  234.  
  235. Instring resb 256
WebN
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,540
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 704
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Nasm to tasm code help

 
0
  #2
Mar 18th, 2006
>Is there someone who could help me convert this to Tasm style.
I'm curious why you asked us instead of the original author on alt.lang.asm. But if you insist on doing things the hard way, your best option is to learn enough TASM to notice the differences and the similarities. Then you can make the conversion yourself. Presumably you already have TASM, so you're in a good position to experiment with the translation until it works for you.

Might I suggest googling for "NASM TASM differences"?
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC