1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2006
    Rep Power

    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,
    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).
  2. #2
  3. fork while true;
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    May 2005
    England, UK
    Rep Power
    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.

    ;JAMES GABRIELSEN CS2650 Assembler Program #3
    [BITS 16]               ;Set code generation to 16 bit mode
    %include 'exebin.mac'
    [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
       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
       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
    	CMP AL, 00		;checking if al=00
    	JNZ dMon
    	LEA DX,[Sunday]
    	CMP AL,01
    	JNZ dTue
    	LEA DX, [Monday]
    	CMP AL, 02
    	JNZ dWed
    	LEA DX,[Tuesday]
    	CMP AL,03
    	JNZ dThu
    	LEA DX, [Wednesday]
    	CMP AL, 04
    	JNZ dFri
    	LEA DX,[Thursday]
    	CMP AL,05
    	JNZ dTue
    	LEA DX, [Friday]
    	CMP AL, 06
    	JNZ dSun
    	LEA DX,[Saturday]
       mov ah,09h		;function 09h (Display string at present cursor location)	
    	int 21H
    stop:  	int 20H
    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, $'
  4. #3
  5. Commie Mutant Traitor
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Jun 2004
    Alpharetta, GA
    Rep Power
    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.
    Rev First Speaker Schol-R-LEA;2 JAM LCF ELF KoR KCO BiWM TGIF
    #define KINSEY (rand() % 7) λ Scheme is the Red Pill
    Scheme in Short Understanding the C/C++ Preprocessor
    Taming Python A Highly Opinionated Review of Programming Languages for the Novice, v1.1

    FOR SALE: One ShapeSystem 2300 CMD, extensively modified for human use. Includes s/w for anthro, transgender, sex-appeal enhance, & Gillian Anderson and Jason D. Poit clone forms. Some wear. $4500 obo. tverres@et.ins.gov

IMN logo majestic logo threadwatch logo seochat tools logo