The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages - More
> Other Programming Languages
|
Beginning Assembly Troubles
Discuss Beginning Assembly Troubles in the Other Programming Languages forum on Dev Shed. Beginning Assembly Troubles A place for discussing programming languages not covered in specific forums such as Assembler, COBOL, etc. - you get the idea.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

August 1st, 2006, 12:53 AM
|
|
Registered User
|
|
Join Date: Jul 2006
Posts: 4
Time spent in forums: 2 h 53 m 47 sec
Reputation Power: 0
|
|
|
Beginning Assembly Troubles
In a computer architecture course that I'm taking, I have to write an x86 assembly program that displays information in the following format,
Code:
John Locke
Monday, July 25, 2006 @ 04:30pm
where the first line is my own name, and the second line is the system date and time.
I've got everything working just fine until I try to display the day of the week. The program compiles just fine in NASM, but after displaying my name, the program stops. It seems to be calculating, but never gets anywhere.
Can anybody help me figure out what's wrong?
This is the assignment description.
This is my progress so far (ZIP file containing the .ASM file).
|

August 2nd, 2006, 06:40 PM
|
 |
fork while true;
|
|
Join Date: May 2005
Location: England, UK
|
|
Is there any reason you couldn't have just posted your script in [ code ] tags?
I'm going to do that for you... I assume it's windows asm, although i don't know for sure.
Code:
;JAMES GABRIELSEN CS2650 Assembler Program #3
[BITS 16] ;Set code generation to 16 bit mode
%include 'exebin.mac'
EXE_Begin
[ORG 100H] ;set addressing to begin at 100H
;**********Clearing the Screen**********
cls: ;clearing the screen
mov ah,06 ;Clear/Scroll Screen Up
mov cx,0000 ;Upper left corner
mov dx,184fH ;Lower right corner
mov al,00 ;blank entire window
mov bh,1fH ;make blanketed area blue
int 10H ;call the interrupt with the preceeding properties
dspName:
mov ah,02h ;function 02h (Position the cursor)
mov al,0 ;Write mode is zero
mov bh,0 ;Use video page of zero
mov dh,12 ;position on row 12
mov dl,00 ;and column 0
int 10H
mov ah,09h ;function 09h (Display string at present cursor location)
lea dx,[Name] ;load the offset address of string into DX
int 21H
dspDoW:
mov ah,02h ;function 02h (Position the cursor)
mov al,0 ;Write mode is zero
mov bh,0 ;Use video page of zero
mov dh,13 ;position on row 13
mov dl,00 ;and column 0
int 10H
mov AH,2aH
int 21 ;reading the clock date
dSun:
CMP AL, 00 ;checking if al=00
JNZ dMon
LEA DX,[Sunday]
dMon:
CMP AL,01
JNZ dTue
LEA DX, [Monday]
dTue:
CMP AL, 02
JNZ dWed
LEA DX,[Tuesday]
dWed:
CMP AL,03
JNZ dThu
LEA DX, [Wednesday]
dThu:
CMP AL, 04
JNZ dFri
LEA DX,[Thursday]
dFri:
CMP AL,05
JNZ dTue
LEA DX, [Friday]
dSat:
CMP AL, 06
JNZ dSun
LEA DX,[Saturday]
mov ah,09h ;function 09h (Display string at present cursor location)
int 21H
stop: int 20H
Vars:
Name: db 'James Gabrielsen$'
Sunday:db 'Sunday, $'
Monday:db 'Monday, $'
Tuesday:db 'Tuesday, $'
Wednesday:db 'Wednesday, $'
Thursday:db 'Thursday, $'
Friday:db 'Friday, $'
Saturday:db 'Saturday, $'
EXE_End
|

August 5th, 2006, 05:49 PM
|
 |
Commie Mutant Traitor
|
|
Join Date: Jun 2004
Location: Norcross, GA (again)
|
|
Actually, LP, it's DOS assembly (it uses the DOS and BIOS interrupts), though it will run under Windows of course.
OK, a few things I've noticed offhand. First off, you don't actually need to include the exebin.mac file, as you don't seem to be using any macros. Mind you, it maybe that there are some macros you could use, but I'd need to see the macros your professor has set up to be sure. I assume it's something that your professor requires you to include, though.
Second, you are getting the day and date info, but then overwriting the date part when you load the address of the day string into DX (which keep in mind is general-purpose register D, full register). According to the interrupt list, the INT 0x21, function 0x2A DOS call (get system time) deposits the month into DH (General register D, high or upper half), and the day of the month into DL (General register D, lower half). You need to save those two values somewhere first, or else you'll lose them, and won't have the value later when you go to print the rest of the date. You haven't done that part of it yet, so it's not a big deal, but you'll need to have that for the final version later. I think that BH and BL should be free at this point; if not, you can use 'resb' ('reserve byte') to set aside some memory variables.
The main thing I see, though, is that you are letting the values fall through after it finds the correct value; that is to say,if it finds a value of zero, then it continues testing the results for all the others. You should have it jump to the end of the switch instead.
Finally, you don't have any sort of default or failure-mode handling; if a value is out of bounds, you have it jump back to the top without changing it, which would give an infinite loop. Since the value given by DOS shouldn't ever be above 6, this probably will never happen, but you might want to have a final 'dBad' case instead of jumping back to dSun just as a matter of sanity checking. This combined with the issue above may well be the source of the problem.
While testing the problem, you might want to start by trying to set it to print a fixed one of the strings, such as sunday. If that works, then the problem must be in the logic; otherwise, the problem is probably with the call to the DOS routine.
On a purely minor note, I might add that it would be slightly more efficient in terms of overall size (and avoid a trivial amount of redundancy) if you eliminated the spaces and the comma in the strings themselves, and printed it out separately. There would be a bit of extra overhead from the extra call, though. Which you do is a matter of personal coding aesthetics, really.
Also, I would have used a table lookup of some sort rather than a switch, but I don't know if your professor has covered enough that you would know how to do that yet; from the problem description, I gather that this is how he is expecting you to do this, so it's just as well.
Last edited by Schol-R-LEA : August 5th, 2006 at 06:38 PM.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|