Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Working with arrays

Status
Not open for further replies.

lilnan

Programmer
Nov 16, 2007
3
US
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!!

 
> 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.
 
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.
 
Perhaps
[tt]_showText ax[/tt]
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.
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top