CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Threaded View

  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.

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