Question

I am trying to read input from the keyboard in 8086. The program will take in two inputs (both integers between -127 and 127), and an operand (either a '*' or a '+').Afterwards I am to solve the expression given, and print it out underneath the other prompts

How do i get the actual value of the number to preform the operation on. When I read it, it puts it as hex ascii value. The number an be negative or positive and can be three digits long

ex:

enter a number: 5 enter another number: 4 operation: *

5 * 4 = 20


As of right now I have created a prompt for each of the inputs and can correctly read them, the problem is,what do I do with the input? How do I use it for an operation Below is my code. Thank you in advance.

;------------------------------------------------
stacksg segment     para stack'Stack'   ;define the stacks
db  32 dup(0)
stacksg ends
;------------------------------------------------
datasg segment para'Data'   ;data segment
paralist label byte
maxlen:   db    5  ;The maximum length of the string will be 20
actlen:   db    ?  ;Which character we have inputed now
buffer:   db    5("$")  ;The buffer where the string is buffered
prompt1 db "Enter the first number:$"
prompt2 db "Enter the second number:$"
prompt3 db "Enter the operation:$"
datasg ends
;-------------------------------------------------
codesg segment para'Code'   ;code segment
            main  proc  far             ;main procedure
    assume ss:stacksg, ds:datasg, cs:codesg ;define segment register
    mov     ax,datasg   ;initialize data segment register
    mov     ds,ax
    mov     es,ax

    mov ah, 06h ;scroll screen  
    mov al, 0   ;num of rows
    mov cx, 0   ;start row
    mov dh, 24  ;end row
    mov dl, 79  ;end col
    mov bh, 30h ;color
    int 10h     ;screen interrupt

    mov ah, 02h
    mov bh, 00h
    mov dh, 10
    mov dl, 20
    int 10h

        ;The First Number
    mov ah,09h
    lea dx,prompt1
    int 21h ;First Input 
    mov ah,0ah
    lea dx,paralist
    int 21h
        mov     ax,4c00h    ;end processing
    int     21h

main    endp                ;end of procedure
codesg  ends                ;end of code segment
    end     main        ;end of program
Was it helpful?

Solution 2

Compare the operator to '+'. If equal, add the two values. If not equal, multiply the two values. Print the result.

Let me fill in some gaps. You will need a loop to convert the characters to numbers

If the first character is '-' set the value to -1 otherwise set it to 1.

a) Subtract '0' from each character and multiply the result by that.

If there are more characters, multiple the result by 10 and goto a).

OTHER TIPS

To get a numeric value of a digit subtract 48 from the value you got as an input (or subtract the value corresponding to ASCII character '0'). Apply this to each one of your digits and you're good to go. See ASCII table for reference.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top