1

I'm using MASM and dosBOX

Basically I have to create a top 10 based on the time someone took to finish a maze.

I started by resetting the system time to 0 when the user passes through the initial character of the maze by doing this:

mov   ah, 2Dh
mov   ch, 00
mov   cl, 00
mov   dh, 00
int   21h

And then when the user reaches the end of the maze i get the system time again and store the time in 2 variables.

mov   ah, 2Ch
int   21h
mov   Final_Min, cl
mov   Final_Sec, dh

Now my problem is , how do i convert those "Final_Min" to seconds and add them to "Final_Sec" so i can get the total time someone took to finish the maze and how do I store these values in an array ?

1 Answers1

1

Minutes come in byte size (cl), but once converted to seconds they will not fit in a byte, so we have to work with word size variables :

Final_Min  dw ?           ;WORD SIZE VARIABLES.
Final_Sec  dw ?
Total_Time dw ?
array      dw 10 dup(?)

  mov  ah, 2Ch
  int  21h                ;GET TIME.

;▼ MOVE BYTE SIZE MINUTES INTO WORD SIZE VARIABLE.  

  xor  ch, ch
  mov  Final_Min, cx      ;MINUTES FROM CL.

;▼ MOVE BYTE SIZE SECONDS INTO WORD SIZE VARIABLE.  

  mov  dl, dh
  xor  dh, dh
  mov  Final_Sec, dx      ;SECONDS FROM DH.

;▼ CONVERT MINUTES TO SECONDS AND ADD THEM.

  mov  ax, Final_Min
  mov  bx, 60
  mul  bx                 ;AX * BX = DX:AX.   
  add  ax, Final_Sec
  mov  Total_Time, ax

;▼ MOVE TOTAL TIME TO FOURTH POSITION IN ARRAY.

  mov  ax, Total_Time
  lea  si, array
  mov  si + 6, ax         ;0=FIRST, 2=SECOND, 4=THIRD, 6=FOURTH.
  • My man , thank you so much. How would I go on about displaying this array ? I assume I can't use int 09h due to there being no "$" at the end of the array. – Gabriel Silva Jun 01 '17 at 22:08
  • 1
    @GabrielSilva, next answer of mine includes the procedure `number2string`, with this procedure you can convert the numbers in your array into string, then you can display the string with `ah=09h` : https://stackoverflow.com/a/30244131/3298930 – Jose Manuel Abarca Rodríguez Jun 01 '17 at 22:15
  • You are a life saver. – Gabriel Silva Jun 01 '17 at 23:29
  • Do you happen to have a link on how I can store information in a file to an array but like array[1] would be the first line of the file , array[2] would be second and so on and how would I compare the values in said array with , in this case , Total_time ? – Gabriel Silva Jun 02 '17 at 15:03
  • @GabrielSilva, it's easy : you convert each number from array into a string (with `number2string`), then you write the string to a file with this another answer of mine (upvote if useful :) ► https://stackoverflow.com/a/29545526/3298930 – Jose Manuel Abarca Rodríguez Jun 02 '17 at 15:10
  • 1
    @GabrielSilva, wait, I think I understood wrong : do you want to read **from** a file, not write **to** a file, and store the strings in an array, convert each string in number (with my `string2number`) and compare? Well, no, I don't have any link to a such specific question. But you can post another question to do that, the problem is, in StackOverflow you have to include your code, or your question will be closed, so you have to try to do it yourself, then you post a question with that code. – Jose Manuel Abarca Rodríguez Jun 02 '17 at 15:23
  • 1
    I'll tell you the algorithm : **1-** make `si` to point to the array, **2-** make `di` to point to a string, **3-** read char by char from the file until end of file, **4-** each char will be stored in `[di]` and increase `di`, **5-** when chars 13 and/or 10 are read the string is converted to number and stored in `[si]` and increase `si`, **6-** make `di` to point to the beginning of the string (again). – Jose Manuel Abarca Rodríguez Jun 02 '17 at 15:34
  • 1
    You didn't understand me wrong , I want to do both so this'll work. I'll give it a try today and make a new post in case it's not working. Thank you so much dude. – Gabriel Silva Jun 03 '17 at 10:47