Ionut Ciochinaru
Ionut Ciochinaru

Reputation: 17

X86 Assembly I want to get a number from my keyboard and compare it, after that I want to print a message

I want to get a number from my keyboard and compare it, after that I want to print a message. Here is my code...

My problem: When I get something from the keyboard, I can press any key and it still says 'PC:Salut'. The program runs without comparing. I want to press 1 and the program to know that 1 corespunds with Romana_Salut.

DATA SEGMENT

    m1 DB 'Chose one of the numbers',10,'$'
    m2 DB '1.Romana',10,'$'
    m3 DB '2.Engleza',10,'$'
    m4 DB '3.Germana',10,'$'
    m5 DB '4.Spaniola',10,'$'

    STR1 DB "ME:->$"
    STR3 DB 'PC:Salut',10,'$'
    STR4 DB 'PC:Hi',10,'$'
    STR5 DB 'PC:Bonjour',10,'$'
    STR6 DB 'PC:Guten Tag',10,'$'
    STR7 DB 'PC:Hola',10,'$'
    STR8 DB 'End',10,'$'
    LinieNoua DB 10,13,"$"
    alg DB 0




DATA ENDS

CODE SEGMENT

    ASSUME DS:DATA,CS:CODE
START:

;intializez segmentul de date

MOV AX,DATA
MOV DS,AX


mov ah,9h
mov dx,offset m1
int 21h

mov ah,9h
mov dx,offset m2
int 21h

mov ah,9h
mov dx,offset m3
int 21h

mov ah,9h
mov dx,offset m4
int 21h

mov ah,9h
mov dx,offset m5
int 21h


Alegerea:

mov dx,offset STR1
mov ah,1
int 21h
mov ch,ah


Romana_Salut:

cmp ch, 1
je Algromana


Algromana:

MOV AH,09H
LEA DX,LinieNoua
INT 21H

mov ah,9h
mov dx,offset STR3
int 21h
jmp Final

Final:

mov ah,4ch
int 21h

CODE ENDS
END START

Upvotes: 1

Views: 205

Answers (1)

AmirSojoodi
AmirSojoodi

Reputation: 1340

You didn't compare the character correctly:

DATA SEGMENT

    m1 DB 'Alege unul dintre numere pentru a afla cum se spune Salut in urmatoarele limbi',10,'$'
    m2 DB '1.Romana',10,'$'
    m3 DB '2.Engleza',10,'$'
    m4 DB '3.Germana',10,'$'
    m5 DB '4.Spaniola',10,'$'

    STR1 DB "ME:->$"
    STR3 DB 'PC:Salut',10,'$'
    STR4 DB 'PC:Hi',10,'$'
    STR5 DB 'PC:Bonjour',10,'$'
    STR6 DB 'PC:Guten Tag',10,'$'
    STR7 DB 'PC:Hola',10,'$'
    STR8 DB 'End',10,'$'
    LinieNoua DB 10,13,"$"
    alg DB 0

DATA ENDS

CODE SEGMENT

    ASSUME DS:DATA,CS:CODE
START:

    mov ax, DATA
    mov ds, ax

    mov ah,9h
    mov dx,offset m1
    int 21h

    mov ah,9h
    mov dx,offset m2
    int 21h

    mov ah,9h
    mov dx,offset m3
    int 21h

    mov ah,9h
    mov dx,offset m4
    int 21h

    mov ah,9h
    mov dx,offset m5
    int 21h

Alegerea:

    mov dx,offset STR1; introdu alegerea...
    int 21h
    mov ah,1h ;citesc alegerea
    int 21h

    cmp al, '1'
    je  Romana_label

    cmp al, '2'
    je  Engleza_label

    cmp al, '3'
    je  Germana_label

    cmp al, '4'
    je  Spaniola_label

Romana_label:

    MOV AH,09H
    LEA DX,LinieNoua
    INT 21H

    mov ah,9h
    mov dx,offset STR3
    int 21h
    jmp Final

Engleza_label:

    MOV AH,09H
    LEA DX,LinieNoua
    INT 21H

    mov ah,9h
    mov dx,offset STR4
    int 21h
    jmp Final

Germana_label:

    MOV AH,09H
    LEA DX,LinieNoua
    INT 21H

    mov ah,9h
    mov dx,offset STR5
    int 21h
    jmp Final

Spaniola_label:

    MOV AH,09H
    LEA DX,LinieNoua
    INT 21H

    mov ah,9h
    mov dx,offset STR6
    int 21h
    jmp Final


Final:

    mov ah,4ch
    mov al,0
    int 21h

CODE ENDS
END START

It is tested with tasm(masm) and link in DOSBox. .....................................................................................................................................................................

I edited so it matches what I intendet for the program to be.

Thank you SonOfSun!

Upvotes: 1

Related Questions