News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Assembly Prgoramming using MASM32.. help needed please

Started by Anan786, March 25, 2007, 11:56:24 PM

Previous topic - Next topic

Anan786

Khan, Anan
CSC210
March 22nd, 2007
Project # 3

Ok my problem is that the professor says the code can be written in a pagehow i have been working on it for days.. someone please help me.. he also said we do not need the conditions.. such as cmp, jg, jle since he thinks we are too novice for it.. but i managed so read up an extra chapter from teh textbook using Kip Irvine's Assembly Languages for Intel based computers... etc. =(, its due tommorow..someone please help.. is there any way someone can write this code a shorter way.. basically all thats needed is for a user to input  the month, day, and year in number form, like 12, 28, 2007.. and the output should be December 28, 2007; day 362 of the year.Our third project will be to convert numerical dates into human dates, and also give which day out of 365 the day represents.  All dates will be from 2000 to 2099; pretend that every year has just 365 days.. someone please help me... please i have been working on this for days.. and i dont see hwo i can shorten the code.. but he says there are ways. .



INCLUDE Irvine32.inc
.data

months BYTE "January",0,0,0
BYTE "February",0,0
BYTE "March",0,0,0,0,0
BYTE "April",0,0,0,0,0
BYTE "May",0,0,0,0,0,0,0
BYTE "June",0,0,0,0,0,0
BYTE "July",0,0,0,0,0,0
BYTE "August",0,0,0,0
BYTE "September",0
BYTE "October",0,0,0
BYTE "November",0,0
BYTE "December",0,0

days DWORD 0,31,59,90,120,151,181,212,243,273,304,334

month DWORD ?
day DWORD ?
year DWORD ?


myMSG1 BYTE "** Project 3 | by: khan, Anan **",0
myMSG2 BYTE "*********************************************",0
myMSG3 BYTE "** This program converts any given date to **",0
myMSG4 BYTE "** human notation and also tells which day **",0
myMSG5 BYTE "** of the year it is. **",0

instruct BYTE "* Enter zero(0) at anytime to Terminate **",0
monthQ BYTE "Enter Your Month (1-12): ",0
dayQ BYTE "Enter Your Day (1-31): ",0
yearQ BYTE "Enter Your Year (01-07): ",0
dayNum BYTE "This is day # ",0
findayNum BYTE " of the year ",0
sessEnd BYTE "Program Has Been Terminated!",0
comma BYTE ", ",0
period BYTE ".",0

.code
main PROC

display:
call Clrscr
mov edx,OFFSET myMSG2
call WriteString
call Crlf
mov edx,OFFSET myMSG1
call WriteString
call Crlf
mov edx,OFFSET myMSG2
call WriteString
call Crlf
mov edx,OFFSET myMSG3
call WriteString
call Crlf
mov edx,OFFSET myMSG4
call WriteString
call Crlf
mov edx,OFFSET myMSG5
call WriteString
call Crlf
mov edx,OFFSET myMSG2
call WriteString
call Crlf
call Crlf

begining:
mov edx, OFFSET myMSG2
call WriteString
call Crlf
mov edx, OFFSET instruct
call WriteString
call Crlf
mov edx, OFFSET myMSG2
call WriteString
call Crlf


;INPUT FROM USER: Month

mov edx, OFFSET monthQ
call Crlf
call Crlf
call WriteString
call ReadInt

;CHECKING...
cmp eax, 0
jle quitting
cmp eax, 12
jg begining


;INPUT FROM USER: Day
dayLabel:
mov month, eax
mov edx, OFFSET dayQ
call Crlf
call WriteString
call ReadInt

;CHECKING...
cmp eax, 0
jle quitting
cmp eax, 31
jg dayLabel

;INPUT FROM USER: Year
yearLabel:
mov day, eax
mov edx, OFFSET yearQ
call Crlf
call WriteString
call ReadInt
mov year, eax

;CHECKING...
cmp eax, 2000
jle quitting
cmp eax, 3000
jg yearLabel

;CALCULATING THE INFORMATION

mov eax, month
sub eax, 1
mov ebx, 10
imul ebx
add eax, OFFSET months
mov edx, eax
call WriteString
mov edx, OFFSET comma
call WriteString
mov eax, day
call WriteDec
call WriteString
mov eax, year
call WriteDec
call Crlf

;DAYS in the year

call Crlf
call Crlf
mov esi, OFFSET days
mov ebx, month
dec ebx
mov eax, 4
imul ebx
mov eax, [esi+eax]
add eax, day
mov edx, OFFSET dayNum
call WriteString
call WriteDec
mov edx, OFFSET findayNum
call WriteString
mov eax, year
call WriteDec
mov edx, OFFSET period
call WriteString
call Crlf

;Going Back - Performs a loop to the begining,
; clearing the screen after the user presses any key
call WaitMsg
call Clrscr
jmp begining


quitting:
call Crlf
call Crlf
mov edx, OFFSET sessEnd
call WriteString
call Crlf

exit
main ENDP

END main

hutch--

Anan,

No-one will do your homework for you but if you break the test piece up into bits and you may get help that way. You need to understand what the procedures in Kip Irvines llibrary do and make sure you are calling them properly.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

MichaelW

One way to make the code shorter would be to take code sequences that are repeated more than about two times, for example:

mov edx,OFFSET myMSG2
call WriteString
call Crlf

And put them in a procedure (don't forget the return instruction), and replace each occurrence of these instructions with a call to the procedure.

Another way would be to take individual strings that are always displayed together, for example:

myMSG3 BYTE "** This program converts any given date to **",0
myMSG4 BYTE "** human notation and also tells which day **",0
myMSG5 BYTE "** of the year it is. **",0

And turn them into a single string that can be displayed in a single call to WriteString. To do this you would replace the zero bytes on myMSG3 and myMSG4 with a CR (byte value 13) followed by a LF (byte value 10). This will work because the function that WriteString calls to display the string knows that a CR means to move the text cursor to the start of the line, and that LF means to move the text cursor to the next line.

BTW, your code is directing the user to input the year as 2 digits in the range 01-07, when it actually needs to be input as 4 digits, and the range can be 2001-3000.
eschew obfuscation