CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jul 2007
    Location
    somwhere nearby
    Posts
    150

    [RESOLVED] help on a simple assembly program

    hello all .
    there is a simple program in assembly which one of my friends gave me to fix it,! but i myself couldnt help it . so i gave it up!
    the program is supposed to be a simple caclulator , which lets the user , add , subtract, divide and multiply two numbers .
    i made the program simpler by removing unnecessary codes , so that only the core codes remain .
    the program works with mouse in Dos assembly , and for knowing onwhich button the user clicked , it uses colors ( interrupt 10H, gets the pixel color under the cursor)
    . the problem is it seems , it can not recognize the colors! ( the conditions are useless !!
    here is the code , hope some helps me
    and i also attached the masm and link and the needed header for compilation if needs be .
    Code:
    include io.h
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Macro;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    Button    MACRO    COLOR,X1,Y1,X2,Y2
    
        MOV AH,06H
        MOV BH,COLOR
        MOV CH,X1
        MOV CL,Y1
        MOV DH,X2
        MOV DL,Y2
        INT 10H
    
    ENDM
    
    ;=============================
    PRINT_MSG    MACRO    MSG
         MOV      DX, OFFSET MSG
         MOV      AH, 9H
         INT      21H
    ENDM
    
    ;****************************
    GOTOXY MACRO X1,Y1
        MOV AH,2
              MOV DL,X1
            MOV DH,Y1  
        MOV BH,0
              INT 10H
    ENDM
    
    ;!!!!!!!CLEAR SCREEN!!!!!!!!!
    CLS    MACRO    COLOR
            MOV    AX , 0600H
            MOV    BH , COLOR
            MOV    CX , 0000H
            MOV    DX , 204FH
            INT    10H
    ENDM
    
    ;==========================
    
    DELAY    MACRO TIME
        LOCAL LBLDELAY2
        LOCAL LBLDELAY1
        LOCAL LBLDELAY0
    
            MOV    BX,TIME
    LBLDELAY2:
            MOV    DX,TIME
    LBLDELAY1:        
            MOV    CX,TIME
    LBLDELAY0:
            NOP
            LOOP    LBLDELAY0        
            DEC    DX
            JNZ    LBLDELAY1
            DEC    BX
            JNZ    LBLDELAY2
        
    ENDM
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    CALCULATORSHAPE Macro
    
        BUTTON 16,1,1,2,4
        BUTTON 32,1,6,2,9
        BUTTON 64,1,11,2,14
        BUTTON 128,1,16,2,19
        BUTTON 200,1,21,2,24
    
    ;;;  buttons labels ;;;
        
        GotoXY  2,2
        PRINT_MSG _1
             
        GotoXY 7,2
        PRINT_MSG _2
        
        GotoXY 12,2
        PRINT_MSG _3
        
        GotoXY 17,2
        PRINT_MSG _4
        
        GotoXY 22,2
        PRINT_MSG _ex
        
    ENDM
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Stack Segment;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    
    STACK SEGMENT
         Dw 100H DUP(?)
    STACK ENDS
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Data Segment;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    
    
    DATA SEGMENT
        
        _0      DB       '0',"$"
        _1      DB       '1',"$"
        _2      DB       '2',"$"
        _3      DB       '3',"$"
        _4      DB       '4',"$"
        _ex      DB       'END',"$"
        
        DIGIT DB 0
        COUNTER DW 0
        ERRORMSG DB 'COLOR NOT DEFINED',0    
        STRING DB 8 DUP('0'),0
    
    
    DATA ENDS
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Code Segment;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    
    CODE SEGMENT
    
    MAIN PROC FAR
    ASSUME CS:CODE, DS:DATA, SS:STACK
    
        MOV AX,SEG DATA
        MOV DS,AX 
        ;.SALL 
                    
    ;;;;;;;;;;;;;;;Get Current Graphic Mode;;;;;;;;;;;
    
        MOV AH , 0FH
        INT  10H         
        MOV AH , 0
        PUSH  AX
    
    ;;    Set New Graphic Mode    ;;
    
        MOV AH , 00H
        MOV AL , 03H
        INT  10H
    
        CALCULATORSHAPE
        
    ;;    Show Mouse    ;;
    
        Mov AX , 01H
        INT 33H
    
    Mouse:    
    
        Mov AX , 03H        ;waiting for user's click
        INT 33H
        
        CMP  BX , 0001H        ;check left click
        JNE   Mouse
    
        
    ;;;READ PIXEL UNDER CURSOR;;
     
        DEC CX
        MOV AH,0DH
        MOV BH,0
        INT 10H
        INC CX
        
    ;; SEE WHICH BUTTON(COLOR) WAS CLICKED    ;;    
    
        CMP AL,16    ;one
        JE ONE    
    
        CMP AL,32    ;two
        JE TWO
    
        CMP AL,64    ;three
        JE THREE
    
        CMP AL,128    ;four
        JE FOUR
        
        CMP AL,200    ;exit
        JE EXIT
        
        
        GOTOXY 30,10    ;none of above
        LEA SI,ERRORMSG  ; show error : 'color is not defined' 
        CALL PUTS
        
        JMP MOUSE
        
        
    ONE:
        MOV DIGIT,'1'
        CALL GETDigit
        JMP MOUSE
    
    TWO:
        MOV DIGIT,'2'
        CALL GETDigit
        JMP MOUSE
    
    THREE:
        MOV DIGIT,'3'
        CALL GETDigit
        JMP MOUSE    
        
    
    FOUR:
        MOV DIGIT,'4'
        CALL GETDigit
        JMP MOUSE        
    
        
    Exit:
    
    ;;;;;;;;;;ReStore Graphic Mode;;;;;;;;
    
           POP  AX
           Mov AH , 0
           INT  10H
    
           MOV AX,4C00H
           INT 21H
    
    MAIN     ENDP
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;            Functions                ;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    
    GETDigit PROC
    
        MOV DL,DIGIT
        LEA DI, STRING
        MOV BX,COUNTER
        CMP BX,8
        JG Ex    
        MOV BYTE PTR[DI+BX] , DL
        INC BX
        MOV COUNTER ,BX
        LEA SI,STRING
        GOTOXY 8,20
        CALL PUTS
    Ex:    
        RET 
    GETDigit ENDP
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;              PUTC                   ;; 
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    PUTC PROC
            PUSH AX
            PUSH BX
           MOV AH, 0EH
           MOV BL, 07H
           MOV BH, 00H
           INT 10H
           POP BX
           POP AX
    RET
    PUTC ENDP
    ;========================================
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;              PUTS                   ;; 
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;LEA SI, YOURTEXT
    PUTS PROC
           PUSH AX
    _PUT:  LODSB
           CMP AL, 0
           JZ _EXIT
           CALL PUTC
           JMP _PUT
    _EXIT:
       POP AX
       RET
    PUTS ENDP   
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    
    
    CODE ENDS
          END MAIN
    Attached Files Attached Files
    Last edited by Master.; August 7th, 2011 at 01:56 AM.

  2. #2
    Join Date
    Jul 2007
    Location
    somwhere nearby
    Posts
    150

    Re: help on a simple assembly program

    ok , thanks to god i found it .
    its all because of that line :
    MOV AL , 03H
    when setting new graphics mode , it must be 12h instead of that 3!
    and thats why those color codes were not working.
    the correct code is :
    Code:
    include io.h
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Macro;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    Button	MACRO	COLOR,X1,Y1,X2,Y2
    
    	MOV AH,06H
    	MOV BH,COLOR
    	MOV CH,X1
    	MOV CL,Y1
    	MOV DH,X2
    	MOV DL,Y2
    	INT 10H
    
    ENDM
    ;!!!!!!!!!!!!Saves registers!!!!!!!!!!!!!!!!!!		 
    pushreg	MACRO
    		PUSH	AX
    		PUSH	BX
    		PUSH	CX
    		PUSH	DX
    		ENDM
    ;!!!!!!!!!!!!Loads registers!!!!!!!!!!!!!!!!!!		
    Popreg	MACRO
    		POP	DX
    		POP	CX
    		POP	BX
    		POP	AX
    		ENDM
    ;=============================
    PRINT_MSG	MACRO	MSG
    	 MOV      DX, OFFSET MSG
         MOV      AH, 9H
         INT      21H
    ENDM
    
    ;****************************
    GOTOXY MACRO X1,Y1
    	MOV AH,2
          	MOV DL,X1
        	MOV DH,Y1  
    	MOV BH,0
          	INT 10H
    ENDM
    
    ;!!!!!!!CLEAR SCREEN!!!!!!!!!
    CLS	MACRO	COLOR
            MOV	AX , 0600H
            MOV	BH , COLOR
            MOV	CX , 0000H
            MOV	DX , 204FH
            INT	10H
    ENDM
    
    ;==========================
    
    DELAY	MACRO TIME
    	LOCAL LBLDELAY2
    	LOCAL LBLDELAY1
    	LOCAL LBLDELAY0
    
    		MOV	BX,TIME
    LBLDELAY2:
    		MOV	DX,TIME
    LBLDELAY1:		
    		MOV	CX,TIME
    LBLDELAY0:
    		NOP
    		LOOP	LBLDELAY0		
    		DEC	DX
    		JNZ	LBLDELAY1
    		DEC	BX
    		JNZ	LBLDELAY2
    	
    ENDM
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    CALCULATORSHAPE Macro
    
    	BUTTON 1,1,1,2,4
    	BUTTON 2,1,6,2,9
    	BUTTON 3,1,11,2,14
    	BUTTON 4,1,16,2,19
    	BUTTON 9,1,21,2,24
    
    ;;;  buttons labels ;;;
    	
    	GotoXY  2,2
        PRINT_MSG _1
             
    	GotoXY 7,2
        PRINT_MSG _2
        
    	GotoXY 12,2
        PRINT_MSG _3
        
    	GotoXY 17,2
        PRINT_MSG _4
        
    	GotoXY 22,2
        PRINT_MSG _ex
    	
    ENDM
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Stack Segment;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    
    STACK SEGMENT
         Dw 100H DUP(?)
    STACK ENDS
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Data Segment;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    
    
    DATA SEGMENT
    	
    	_0      DB       '0',"$"
    	_1      DB       '1',"$"
    	_2      DB       '2',"$"
    	_3      DB       '3',"$"
    	_4      DB       '4',"$"
    	_ex      DB       'END',"$"
    	
    	DIGIT DB 0
    	COUNTER DW 0
    	ERRORMSG DB 'COLOR NOT DEFINED',0	
    	STRING DB 8 DUP('0'),0
    
    
    DATA ENDS
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Code Segment;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    
    CODE SEGMENT
    
    MAIN PROC FAR
    ASSUME CS:CODE, DS:DATA, SS:STACK
    
        MOV AX,SEG DATA
        MOV DS,AX 
        ;.SALL 
                	
    ;;;;;;;;;;;;;;;Get Current Graphic Mode;;;;;;;;;;;
    
    	MOV AH , 0FH
    	INT  10H 		
    	MOV AH , 0
    	PUSH  AX
    
    ;;	Set New Graphic Mode	;;
    
    	MOV AH , 00H
    	MOV AL , 12H ;03
    	INT  10H
    
    	CALCULATORSHAPE
    	
    ;;	Show Mouse	;;
    
    	Mov AX , 01H
    	INT 33H
    
    Mouse:	
    
    	Mov AX , 03H    	;waiting for user's click
    	INT 33H
    
    
    	PUSHreg
    	DELAY 500
    	popreg
    
    
    	
    	CMP  BX , 0001H		;check left click
    	JNE   Mouse
    
    	
    ;;;READ PIXEL UNDER CURSOR;;
     
    	DEC CX
    	MOV AH,0DH
    	MOV BH,0
    	INT 10H
    	INC CX
    	
    ;; SEE WHICH BUTTON(COLOR) WAS CLICKED	;;	
    
    	CMP AL,1	;one
    	JE ONE	
    
    	CMP AL,2	;two
    	JE TWO
    
    	CMP AL,3	;three
    	JE THREE
    
    	CMP AL,4	;four
    	JE FOUR
    	
    	CMP AL,9	;exit
    	JE EXIT
    	
    	
    	GOTOXY 30,10	;none of above
    	LEA SI,ERRORMSG  ; show error : 'color is not defined' 
    	CALL PUTS
    	
    	JMP MOUSE
    	
    	
    ONE:
    	MOV DIGIT,'1'
    	CALL GETDigit
    	JMP MOUSE
    
    TWO:
    	MOV DIGIT,'2'
    	CALL GETDigit
    	JMP MOUSE
    
    THREE:
    	MOV DIGIT,'3'
    	CALL GETDigit
    	JMP MOUSE	
    	
    
    FOUR:
    	MOV DIGIT,'4'
    	CALL GETDigit
    	JMP MOUSE		
    
    	
    Exit:
    
    ;;;;;;;;;;ReStore Graphic Mode;;;;;;;;
    
       	POP  AX
       	Mov AH , 0
       	INT  10H
    
       	MOV AX,4C00H
       	INT 21H
    
    MAIN 	ENDP
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;			Functions 			   ;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    
    GETDigit PROC
    
    	MOV DL,DIGIT
    	LEA DI, STRING
    	MOV BX,COUNTER
    	CMP BX,8
    	JG Ex	
    	MOV BYTE PTR[DI+BX] , DL
    	INC BX
    	MOV COUNTER ,BX
    	LEA SI,STRING
    	GOTOXY 8,20
    	CALL PUTS
    Ex:	
    	RET 
    GETDigit ENDP
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;              PUTC                   ;; 
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    PUTC PROC
    		PUSH AX
    		PUSH BX
    	   MOV AH, 0EH
    	   MOV BL, 07H
    	   MOV BH, 00H
    	   INT 10H
    	   POP BX
    	   POP AX
    RET
    PUTC ENDP
    ;========================================
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;              PUTS                   ;; 
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;LEA SI, YOURTEXT
    PUTS PROC
    	   PUSH AX
    _PUT:  LODSB
    	   CMP AL, 0
    	   JZ _EXIT
    	   CALL PUTC
    	   JMP _PUT
    _EXIT:
       POP AX
       RET
    PUTS ENDP   
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    
    
    CODE ENDS
      	END MAIN

  3. #3
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: help on a simple assembly program

    If that concludes the issue set the thread as resolved.
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    https://visualstudio.microsoft.com/vs

  4. #4
    Join Date
    Jul 2007
    Location
    somwhere nearby
    Posts
    150

    Re: help on a simple assembly program

    Quote Originally Posted by S_M_A View Post
    If that concludes the issue set the thread as resolved.
    sorry but how am i supposed to do that! i dont see any kind of button for such thing!?

  5. #5
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: help on a simple assembly program

    Quote Originally Posted by Master. View Post
    sorry but how am i supposed to do that! i dont see any kind of button for such thing!?
    It's the last item on the "Thread Tools" menu at the top of the thread display. And it's a good habit to make use of that feature.
    Last edited by Eri523; August 8th, 2011 at 10:51 AM.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  6. #6
    Join Date
    Jul 2007
    Location
    somwhere nearby
    Posts
    150

    Re: help on a simple assembly program

    Quote Originally Posted by Eri523 View Post
    It's the last item on the "hTread Tools" menu at the top of the thread display. And it's a good habit to make use of that feature.
    Thanks , i just saw that , never knew we had such a thing here

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured