Need Help writing a Project for class (complete new to this)

Started by dr3am, March 12, 2008, 12:04:54 AM

Previous topic - Next topic

dr3am

Hi  As it says, I am complete new to this and do not understand most of the stuff.  I have to write a project for my class which will display todays date on one line as mm/dd/yyyy and in the next line will display current system time as
ss:mm:hh
I have to use PutDec and _Getdate Macro to get the results

# Return the time using the _GetTime macro (performs a DOS Get Time call) which also is contained in the PCMAC.inc file
# Display the time in the form "Current time is hh:mm:ss


This is my current progress
The month displays corrent but need it to be 03 and it displays just 3

INCLUDE H:\CS17\PCMAC.INC


   .MODEL   SMALL
   .586
   
   
   .STACK   100h
   
   
   .DATA
Slash   DB   '/$'
SaveX   DB   ?
SaveY   DW   ?
      
   
   .CODE
   EXTRN   GetDec : NEAR, PutDec : NEAR
Today   PROC
   _Begin
   _GetDate
   mov   al, dh
   mov   ah, 0
   call   PutDec
   _PutStr   Slash
   _Exit 0
   
Today   EndP

   End




Thanks for all the help :bg

MichaelW

If PutDec will not display leading zeros, then you could examine the value in AX before you call PutDec, and if it's less than 10 display a leading zero. If the macros or procedures that you are using do not preserve all registers, then you will need to add code to preserve the necessary registers.
eschew obfuscation

dr3am

I kind of know what you are saying.  But to actually make that happen is kinda shady to me.  I was hopping if someone would just write up the code for me and paste it hear  :green2 because I have absolutely no idea what to do  ::)

BogdanOntanu

Quote from: dr3am on March 12, 2008, 12:11:56 PM
I was hopping if someone would just write up the code for me and paste it hear  :green2 because I have absolutely no idea what to do  ::)

This would be against the rules of this forum. However we might assist you if show a will to do your own homework.
If you do not feel like being capable to do this them maybe you should choose another class.

Alternatively you could come clean to you teacher and tell him that you have no clue. Maybe he will try to teach you again until you understand something.
Ambition is a lame excuse for the ones not brave enough to be lazy.
http://www.oby.ro

dr3am

alright here is the deal i know that the month is in dh register, the day is in ah register and the year is in ax register,  but my problem is that i don't know how to call them and where to mov them so i can display them correctly.  I have been trying, but this stuff is not working for me.  This class is a requirement for another class (Java for some reason) which does not have that much relevance to it (i think).

That much said can some one LEAD me to right direction as to what i should be doing to get this thing working.

BogdanOntanu

Quote
the day is in ah register and the year is in ax register

How can that be?


What do you have to do and what have you tried and it is not working?
What exactly is not working?

Ambition is a lame excuse for the ones not brave enough to be lazy.
http://www.oby.ro

jj2007

Bogdan, what happened? You are so... I don't find the word: patient? wise?  :cheekygreen:

BogdanOntanu

Quote from: jj2007 on March 12, 2008, 07:08:44 PM
Bogdan, what happened? You are so... I don't find the word: patient? wise?  :cheekygreen:

It is just an illusion... ;)
Ambition is a lame excuse for the ones not brave enough to be lazy.
http://www.oby.ro

dr3am

Come on man can you just help me out here.  this is the only thing i can thing of right now.  because those registers have the date in  them all i have to do is save them to the variable and display them (atleast that is what i am thinking), but it is not working out. 


   .CODE
   
   EXTRN   GetDec : NEAR, PutDec : NEAR
   
Today   PROC
   _Begin
   _GetDate
   mov   al, dh
   mov   ah, 0
   call   PutDec
   mov   SaveY, ax
   mov   SaveX, dl
   _PutStr   Slash
   _PutCh   SaveX
   _PutStr   Slash
   _PutCh   SaveY
   _Exit 0
   
Today   EndP

   End

dr3am

alright I kinda of get the month working also, but the Year is now working here is my updated code


   .DATA
Slash   DB   '/$'
SaveX   DB   ?
SaveY   DW   ?
      
   
   .CODE
   
   EXTRN   GetDec : NEAR, PutDec : NEAR
   
Today   PROC
   _Begin
   _GetDate
   mov   al, dh
   mov   ah, 0
   call   PutDec
   mov   SaveX, dl
   _PutStr   Slash
   mov   dl, SaveX
   mov   al, dl
   mov   ah, 0
   call   PutDec
   _Exit 0

MichaelW

The normal way of preserving a register is on the stack. The stack is a special area of memory that is commonly used for things like saving the return address for a call instruction (the processor does this automatically), passing arguments to procedures, and preserving the values of registers. It is possible to use a pair of mov instructions to preserve the value of a register, as you did with DL and SaveX, but it's more convenient to just use a push and a pop. The push instruction places its operand on the stack, and the pop instruction removes the last value pushed from the stack and places the value in its operand.


    _Begin
    _GetDate
    mov al, dh
    mov ah, 0
    push dx
    call PutDec
    _PutStr Slash
    pop dx
    mov   al, dl
    mov   ah, 0
    call   PutDec
    _Exit 0


But before you bother to preserve the values, you should first determine if the macros in PCMAC.INC, and the procedures that you are using, already preserve all of the registers. I seem to recall that in one implementation of PCMAC.INC that I found, the macros with a leading underscore in the name preserved all of the registers.

Also, did you notice Bogdan's question regarding:

Quotethe day is in ah register and the year is in ax register

Details like this are important if you expect to create code that works correctly.

eschew obfuscation

dr3am

I was told that _PutStr and _PutCh macro destroy the value of registers AX and DX that is why I was trying to save the register value to a variable before i call those macros and later restore the value back to the register using the mov command. (as you can see with my whole code there)  Now when I assemble and link the code and run the program it gives me an answer of 3/12/2084

Also on the count of that the year is in ax register my book here tells me that the year is in CX register, so I don't know.

.DATA
Slash DB '/$'
SaveX DB ?
SaveY DW ?


.CODE

EXTRN GetDec : NEAR, PutDec : NEAR

Today PROC
_Begin
_GetDate
mov al, dh
mov ah, 0
call PutDec
mov SaveX, dl
mov SaveY, cx
_PutStr Slash
mov dl, SaveX
mov al, dl
mov ah, 0
call PutDec
_PutStr Slash
mov cx, SaveY
mov ah, 8
call PutDec
_GetTime
_Exit 0

Today EndP
           End Today

MichaelW

If your copy of PCMAC.INC and UTIL.LIB are the same as mine:

_GetDate returns the year in CX, the month in DH, and the day in DL

PutDec preserves all registers
_PutStr destroys AX and DX
_PutCh destroys AX and DX
sPutStr preserves all registers
sPutCh preserves all registers

For simplicity I would use the versions that preserve all registers. And you will need to add a leading zero on the month. I would use a CMP (compare), a JA (jump above) conditional jump, and a label, arranged so the leading zero would be added only if the month value were < 10.



eschew obfuscation

dr3am

see we haven't got that far where we use all those fancy stuff where we use jumps and sPutCh  requirements are to use _Getdate macro PutDec call util to display the date.  i am using the INC from the cd that came with the book.

MichaelW

I don't see any way you can add the leading zero, properly, without some sort of conditional code. Unless it's OK to just add the leading zero and not worry about the code breaking in 7 months.

Also, your code is not displaying the year correctly because PutDec expects the value in AX, and your code fails to copy the year value in CX to AX.

eschew obfuscation