Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;Write a program that, given two operands opa and opb of type word in memory, of value respectively of 2043 and 5, executes an operation between integers, chosen by user and that saves the result into the word variable 'res'
- ;Depending on the character typed by user, the program must execute:
- ;1 --> res = a+b
- ;2 --> res = a-b
- ;3 --> res = a*b
- ;4 --> res = a/b (integer division)
- ;IMPLEMENTATION
- ;Need to implement a switch construct:
- ; switch (expression)
- ; {
- ; case val1: sequence1;
- ; break;
- ; case val2: sequence2;
- ; break;
- ; ...
- ; default: sequence_def;
- ; }
- ;It's possible use operations of compare and conditional jumps to a blocks of code
- .MODEL small
- .STACK
- .DATA
- opa DW 2043
- opb DW 5
- res DW ?
- .CODE
- .START
- MOV AH,1
- INT 21h
- SUB AL,'0'
- CMP AL,1
- JE sum
- CMP AL,2
- JE subtr
- CMP AL,3
- JE product
- CMP AL,4
- JE division
- JNE ex
- sum: MOV BX,opa
- ADD BX,opb
- MOV res, BX
- JMP ex
- subtr: MOV BX,opa
- SUB BX,opb
- MOV res, BX
- JMP ex
- product: MOV AX,opa
- MOV CX,opb
- MUL CX
- MOV res,AX
- JMP ex
- division: MOV AX,opa
- MOV DX,0 ;If I don't insert this, it gives me problem at overflow. Because the value of DX is changed when the input window appears
- MOV BX,opb
- DIV BX
- MOV res,AX
- JMP ex
- ex:
- .EXIT
- END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement