Good day to everyone

I am having some trouble with an assignment for my work at College in UK (im 17)

We have been given the task of, and the criteria of

The program should allow the user to input 4 numbers as follows:

'0' - Exit the program

'1' - Add (using iteration) all the even numbers up to and including 20

'2' - Input two numbers in the range 0 - 9 and add them together

'3' - Input two numbers in the range 0 - 9 and subtract second from first

The program should repeat until zero is selected.

I have succesfully done 0,1,3 but my Addition is slacking

I have registered to move the result to BL but when it goes there when I enter number 1 it shows 3"#"
then when i add the second number it shows 6"#" although the # is right my teacher tells me it needs to have 3"#" with the answer.. not even my teacher could figure out why this was happening so i am here to ask for a hand

something to be aware of.. if you enter AAA before line 200 would fix the error above but it would show the ascii code instead of the number entered

here is the code

please go to Sums:

Thanks

        JMP BEGIN 
MSG4    DB  'BTEC EXTENDED DIPLOMA in IT- SIMPLE CALCULATOR $' 
        JMP BEGIN
MSG5    DB  'JULY 2012 (ASSIGNMENT 3) $'        
        JMP START        
MSG     DB 'PLEASE CAN YOU ENTER NUMBER 0 TO 3 $' 


MSG3 DB 10,13,'sum = $'
    newline DB 10,13, ' $' 
CAL1 DB 'ENTER FIRST NUMBER: $'
CAL2 DB 'ENTER SECOND NUMBER: $'

        JMP START 


CR      EQU 13D
LF      EQU 10D 

NUMBER      EQU   02
LIMIT       EQU 20 



BEGIN:  MOV DX, OFFSET  MSG4 
        MOV AH, 09
        INT 21H

        MOV DL, CR
        MOV AH, 2H
        INT 21H 

        MOV DL, LF
        MOV AH, 2H
        INT 21H 

        MOV DX, OFFSET  MSG5 
        MOV AH, 09
        INT 21H

        MOV DL, CR
        MOV AH, 2H
        INT 21H 

        MOV DL, LF
        MOV AH, 2H
        INT 21H   

START:  MOV DX, OFFSET  MSG                      
        MOV AH, 09                 
        INT 21H

        MOV DL, CR
        MOV AH, 2H
        INT 21H

        MOV  DL, LF
        MOV  AH, 2H
        INT  21H 

        MOV  AH, 00              ; READ KEYBOARD
        INT  16h                 ;
                                 ;   
        MOV  DL, AL              ;DISPLAY KEY PRESSED
        MOV  AH, 2H              ;
        INT  21H  

        CMP AL, '0'
        JE EXIT



        CMP AL, '1'
        JE ITERATION  


        CMP AL, '2'
        JE   SUMS 


        CMP AL, '3'
        JE SUBTRACTION




SUBTRACTION: MOV DL, CR
             MOV AH, 2H
             INT 21H 

             MOV  DL, LF
             MOV  AH, 2H
             INT  21H 
             MOV DX, OFFSET  CAL1                      
             MOV AH, 09                 
             INT 21H            ;SHOW

             MOV  AH, 00             
             INT  16h           ;INPUT NUMBER    

             MOV  DL, AL              
             MOV  AH, 2H              
             INT  21H
             MOV BL,AL

             MOV DL, CR
             MOV AH, 2H
             INT 21H 

             MOV  DL, LF
             MOV  AH, 2H
             INT  21H 


             MOV DX, OFFSET  CAL2                      
             MOV AH, 09                 
             INT 21H              ; SHOW

             MOV  AH, 00             
             INT  16h             ; INPUT

             SUB BL, AL 

             MOV  DL, AL              
             MOV  AH, 2H              
             INT  21H 
             MOV DL, CR
             MOV AH, 2H
             INT 21H 

             MOV DL, LF
             MOV AH, 2H
             INT 21H  


             JMP START



ITERATION:  MOV DL, CR
            MOV AH, 2H
            INT 21H 

            MOV  DL, LF
            MOV  AH, 2H
            INT  21H 
            MOV BH, NUMBER 
REPEAT:     ADD BL, BH
            ADD BH, NUMBER
            CMP BH, LIMIT
            JNG REPEAT         
            JMP START

SUMS:        MOV DL, CR
             MOV AH, 2H
             INT 21H 

             MOV  DL, LF
             MOV  AH, 2H
             INT  21H  

             MOV DX, OFFSET  CAL1                      
             MOV AH, 09                 
             INT 21H           ; SHOW WORDS


             MOV  AH, 00           
             INT  16h         ; INPUT NUMBER       



             MOV  DL, AL             
             MOV  AH, 2H              
             INT  21H
             MOV BL, AL

             MOV DL, CR
             MOV AH, 2H
             INT 21H 

             MOV  DL, LF
             MOV  AH, 2H
             INT  21H 





             MOV DX, OFFSET  CAL2                      
             MOV AH, 09                 
             INT 21H               ; SHOW WORDS

             MOV  AH, 00             
             INT  16h               ; INPUT NUMBER 


             ADD BL,  AL

             MOV  DL, AL              
             MOV  AH, 2H              
             INT  21H 

             MOV DL, CR
             MOV AH, 2H
             INT 21H 

             MOV DL, LF
             MOV AH, 2H
             INT 21H               

             JMP START 



Exit:   MOV AH, 4CH
        INT 21H
        END     

Boy, you are at a college that is touting itself as being on top of the latest technology and they are using DOS 1.0.

Let's just fix one piece at a time. Zero is not the same as the digit zero '0'. As a matter of fact, it happens to be 30H or 48 decimal ( 0011 0000 ) binary. So what you need to do is strip the high nibble 0000 0000 from the input.

    mov     bl, 0

Again:

    mov     ah, 0
    int     16H

    and     al, 15     Strips scancode from AH and high nibble from AL

    add     bl, al     Need to use 16 bit registers
    jmp     Again

Done:

As per selection "2", if you entered 9 twice the result would be 18 and what you'd see
in BL = 12H. This number needs to be converted to 31H & 38H to show you the proper result on the monitor.

No matter the institution you're attending, if the instructor can't answer a question about an assignment he/she gives, you might want to seriously think about going to a different college.

you are at a college that is touting itself as being on top of the latest technology and they are using DOS 1.0.

Let's just fix one piece at a time. Zero is not the same as the digit zero '0'. As a matter of fact, it happens to be 30H or 48 decimal ( 0011 0000 ) binary. So what you need to do is strip the high nibble 0000 0000 from the input.

I will work on that later, but for now I will tell you that the teacher is a complete fool, taking months to complete marking etc, the college is actually one of the best in europe in terms of getting students to university, I dont think the IT department is all too successful

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.