×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Working with arrays

Working with arrays

Working with arrays

(OP)
I am a beginner and am trying to display the current date. So far I have this but it just keeps printing Sunday which is the first entry in the "DayName" array. I am trying to get the current date from the system to display. Can anyone direct me in what I am doing wrong.
Heres my code...if need to see my macro file let me know.

.DATA
Day_length EQU  11
DayName DB  'Sunday.$   ',
          'Monday.$   ',
          'Tuesday.$  ',
          'Wednesday.$' ,       
          'Thursday.$ ',
          'Friday.$   ',
          'Saturday.$ '
Message     DB    'Today is $'

.CODE
  main    PROC
  _initreg
  _showText Message
  _initreg
  _GetDate
  
  mov bl, Day_length
  imul bl
  mov ax, OFFSET DayName
  
  _showDay DayName
    _endProg

Any help in the right direction would be appreciated!!

Replies continue below

Recommended for you

RE: Working with arrays

> mov ax, OFFSET DayName
Perhaps 'add' rather than 'mov', since mov trashes the result of your carefully prepared multiply.

Oh, and please use [code][/code] tags when posting code.

--
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.

RE: Working with arrays

(OP)
I still get "Today is Sunday." as my result. Am I missing the concept of something? It seems to be just taking the first one on the list.
Heres my .asm and .lib:

CODE

; Macro to initialize registers at program start
_initreg    MACRO
    mov    ax, @data    ; Initialize
    mov    ds, ax        ;   Segment registers

    sub    ax, ax        ; Initialize
    sub    bx, bx        ;   Remaining
    sub    cx, cx        ;     Registers
    sub    dx, dx
    ENDM
; ----------------------------------------------------------
; Macro to terminate program
_endprog    MACRO
        mov     ax, 4c00h    ; End
        int    21h        ;   processing
    ENDM
; ----------------------------------------------------------
; Macro to display text on screen
_showText MACRO strText
    mov    ah, 09h
    lea    dx, strText
    int    21h
    ENDM
; ----------------------------------------------------------
;Macro to get the date
_GetDate MACRO
  mov     ah, 2ah
  int     21h
  ENDM
; ----------------------------------------------------------

CODE

    .DATA
Day_length EQU  11
DayName DB  'Sunday.$   ',
          'Monday.$   ',
          'Tuesday.$  ',
          'Wednesday.$' ,       
          'Thursday.$ ',
          'Friday.$   ',
          'Saturday.$ '
Message     DB    'Today is $'
;-----------------------------------------------------------
    .CODE
  main    PROC
  _initreg
  _showText Message
  _initreg
  _GetDate
  
  mov bl, Day_length
  imul bl
  add ax, OFFSET DayName
  
  _showText DayName
    _endProg

main    ENDP
    END    main

Sorry about code tags in first post. Thanks for letting me know.

RE: Working with arrays

Perhaps
_showText ax
which is the start of the line of interest, rather than always the start of the array.

Investigate to see if you have any kind of debugger available, which would allow you to single-step the code and actually see what it does on a line by line basis.

Though your _showText macro trashes al before you get to load ax into dx.  Consider setting dx first, or use another macro perhaps?


--
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.

RE: Working with arrays

(OP)
Thanks!! I got it. I just moved the ax into another variable and created a new macro as such, to display the correct day:

CODE

_showDay MACRO text
        mov    dx, text    
    mov    ah, 09h
    int    21h
    ENDM

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close