Print out Date & Time Assignment

Reply

Join Date: Apr 2008
Posts: 12
Reputation: defychaos is an unknown quantity at this point 
Solved Threads: 0
defychaos's Avatar
defychaos defychaos is offline Offline
Newbie Poster

Print out Date & Time Assignment

 
0
  #1
Apr 9th, 2008
First post, so go easy on me. I'm hoping an Assembly guru can help me out with my assignment. For some reason, I'm losing my Century when I try to print out date and time in Assembly. Wondering if someone could take a peek and help me out. Also, although I'm pretty certain I've got the display code correct, I can't figure out why it won't print out in my compiled version. Thank you in advance for the help
  1. [BITS 16] ;Set code generation to 16 bit mode
  2. %include 'exebin.mac' ;include file to simulate .com header
  3.  
  4. EXE_Begin ;assembler directive to indicate executable begin
  5.  
  6. [ORG 100H] ;set addressing to begin at 100H
  7.  
  8. start:
  9. call cls ;call routine to clear screen
  10. call dspmsg ;call routine to display message
  11. call date
  12. call cvtmo
  13. call cvtday
  14. call cvtcent
  15. call cvtyear
  16. call dspdate
  17. call time
  18. call cvthrs
  19. call cvtmin
  20. call cvtsec
  21. call dsptime
  22. int 20h ;halt operation (VERY IMPORTANT!!!)
  23.  
  24. cls:
  25. mov ah,06h ;function 06h (Scroll Screen)
  26. mov al,0 ;scroll all lines
  27. mov bh,1FH ;Attribute (bright white on blue)
  28. mov ch,0 ;Upper left row is zero
  29. mov cl,0 ;Upper left column is zero
  30. mov dh,24 ;Lower left row is 24
  31. mov dl,79 ;Lower left column is 79
  32. int 10H ;BIOS Interrupt 10h (video services)
  33. ret
  34.  
  35.  
  36. dspmsg:
  37. mov ah,13h ;function 13h (Display String)
  38. mov al,0 ;Write mode is zero
  39. mov bh,0 ;Use video page of zero
  40. mov bl,00h ;Attribute (bright white on bright blue)
  41. mov cx,8 ;Character string is 25 long
  42. mov dh,3 ;position on row 3
  43. mov dl,0 ;and column 28
  44. push ds ;put ds register on stack
  45. pop es ;pop it into es register
  46. lea bp,[msg] ;load the offset address of string into BP
  47. int 10H
  48. ret
  49.  
  50. msg: db 'My name :D'
  51.  
  52. date:
  53. ;Get date from the system
  54. mov ah,04h ;function 04h (get RTC date)
  55. int 1Ah ;BIOS Interrupt 1Ah (Read Real Time Clock)
  56. ret
  57.  
  58. ;CH - Century
  59. ;CL - Year
  60. ;DH - Month
  61. ;DL - Day
  62.  
  63. cvtmo:
  64. ;Converts the system date from BCD to ASCII
  65. mov bh,dh ;copy contents of month (dh) to bh
  66. shr bh,1
  67. shr bh,1
  68. shr bh,1
  69. shr bh,1
  70. add bh,30h ;add 30h to convert to ascii
  71. mov [dtfld],bh
  72. mov bh,dh
  73. and bh,0fh
  74. add bh,30h
  75. mov [dtfld + 1],bh
  76. ret
  77.  
  78. cvtday:
  79. mov bh,dl ;copy contents of day (dl) to bh
  80. shr bh,1
  81. shr bh,1
  82. shr bh,1
  83. shr bh,1
  84. add bh,30h ;add 30h to convert to ascii
  85. mov [dtfld],bh
  86. mov bh,dl
  87. and bh,0fh
  88. add bh,30h
  89. mov [dtfld +4],bh
  90. ret
  91.  
  92. cvtcent:
  93. mov bh,ch ;copy contents of century (ch) to bh
  94. shr bh,1
  95. shr bh,1
  96. shr bh,1
  97. shr bh,1
  98. add bh,30h ;add 30h to convert to ascii
  99. mov [dtfld],bh
  100. mov bh,ch
  101. and bh,0fh
  102. add bh,30h
  103. mov [dtfld + 7],bh
  104. ret
  105.  
  106. cvtyear:
  107. mov bh,cl ;copy contents of year (cl) to bh
  108. shr bh,1
  109. shr bh,1
  110. shr bh,1
  111. shr bh,1
  112. add bh,30h ;add 30h to convert to ascii
  113. mov [dtfld],bh
  114. mov bh,cl
  115. and bh,0fh
  116. add bh,30h
  117. mov [dtfld + 9],bh
  118. ret
  119.  
  120. dtfld: db '00/00/0000'
  121.  
  122. dspdate:
  123. ;Display the system date
  124. mov ah,13h ;function 13h (Display String)
  125. mov al,0 ;Write mode is zero
  126. mov bh,0 ;Use video page of zero
  127. mov bl,0Fh ;Attribute
  128. mov cx,10 ;Character string is 10 long
  129. mov dh,5 ;position on row 4
  130. mov dl,0 ;and column 28
  131. push ds ;put ds register on stack
  132. pop es ;pop it into es register
  133. lea bp,[dtfld] ;load the offset address of string into BP
  134. int 10H
  135. ret
  136.  
  137. time:
  138. ;Get time from the system
  139. mov ah,02h
  140. int 1Ah
  141. ret
  142.  
  143. ;CH - Hours
  144. ;CL - Minutes
  145. ;DH - Seconds
  146.  
  147. cvthrs:
  148. ;Converts the system time from BCD to ASCII
  149. mov bh,ch ;copy contents of hours (ch) to bh
  150. shr bh,1
  151. shr bh,1
  152. shr bh,1
  153. shr bh,1
  154. add bh,30h ;add 30h to convert to ascii
  155. mov [tmfld],bh
  156. mov bh,ch
  157. and bh,0fh
  158. add bh,30h
  159. mov [tmfld + 1],bh
  160. ret
  161.  
  162. cvtmin:
  163. mov bh,cl ;copy contents of minutes (cl) to bh
  164. shr bh,1
  165. shr bh,1
  166. shr bh,1
  167. shr bh,1
  168. add bh,30h ;add 30h to convert to ascii
  169. mov [tmfld],bh
  170. mov bh,cl
  171. and bh,0fh
  172. add bh,30h
  173. mov [tmfld + 4],bh
  174. ret
  175.  
  176. cvtsec:
  177. mov bh,dh ;copy contents of seconds (dh) to bh
  178. shr bh,1
  179. shr bh,1
  180. shr bh,1
  181. shr bh,1
  182. add bh,30h ;add 30h to convert to ascii
  183. mov [tmfld],bh
  184. mov bh,dh
  185. and bh,0fh
  186. add bh,30h
  187. mov [tmfld + 7],bh
  188. ret
  189.  
  190. tmfld: db '00:00:00'
  191.  
  192. dsptime:
  193. ;Display the system time
  194. mov ah,13h ;function 13h (Display String)
  195. mov al,0 ;Write mode is zero
  196. mov bh,0 ;Use video page of zero
  197. mov bl,0Fh ;Attribute
  198. mov cx,8 ;Character string is 8 long
  199. mov dh,5 ;position on row 5
  200. mov dl,0 ;and column 28
  201. push ds ;put ds register on stack
  202. pop es ;pop it into es register
  203. lea bp,[tmfld] ;load the offset address of string into BP
  204. int 10H
  205. ret
  206.  
  207. int 20H
  208. EXE_End
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 1
Reputation: randz214 is an unknown quantity at this point 
Solved Threads: 0
randz214 randz214 is offline Offline
Newbie Poster

Re: Print out Date & Time Assignment

 
0
  #2
Sep 29th, 2008
Hi I'am a new member of this forum. I came across your code when I was looking for a project. Our project was to make OS Shell Commands using NASM compiler. Then, my partner and I tried to incorporate your work to our "baby OS". I am happy to say that it worked. Up to the point where it outputted the Century where you were having trouble with.

In line 99, we changed [dtfld] to [dtfld + 6]. I hope this helps. And thanks for the idea for our OS command.
Reply With Quote Quick reply to this message  
Reply

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



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