164k views
1 vote
Write a program that reads the following:(Assembly code)

2 Digit number, an operator, then a 2 digit number.

Then, display the formula and the result. You must display your name in the output. So first display your name, followed by the output

Sample Input
12+03

Output
First name last name

12+03=15

Sample Input
02-03

Output
First name last name

03-02=-1

Sample Input
02*11

Output
First name last name

02*11=22

Sample Input
44/21

Output
First name last name

44/21=2 Remainder 2

Sample Input
44/22

Output
First Name Last name

44/22 = 2 Remainder 0

User Zhuanzhou
by
8.2k points

1 Answer

6 votes

Answer: Here's a program in assembly language that reads a two-digit number, an operator, and another two-digit number, and then displays the formula and the result:

```

ORG 100h

MOV AH, 1h ; read first digit

INT 21h

SUB AL, 30h

MOV BL, AL ; save first digit

MOV AH, 1h ; read second digit

INT 21h

SUB AL, 30h

MOV CL, AL ; save second digit

MOV AH, 1h ; read operator

INT 21h

MOV DL, AL ; save operator

MOV AH, 1h ; read third digit

INT 21h

SUB AL, 30h

MOV BH, AL ; save third digit

MOV AH, 1h ; read fourth digit

INT 21h

SUB AL, 30h

MOV CH, AL ; save fourth digit

CMP DL, '+' ; check operator

JE ADDITION

CMP DL, '-' ; check operator

JE SUBTRACTION

CMP DL, '*' ; check operator

JE MULTIPLICATION

CMP DL, '/' ; check operator

JE DIVISION

JMP EXIT

ADDITION:

MOV AL, BL ; move first digit to AL

ADD AL, BH ; add third digit to AL

JC CARRY_ADD

MOV CL, DL ; move operator to CL

MOV AH, 2h ; display formula

INT 21h

MOV AH, 0 ; clear AH

MOV DL, AL ; move result to DL

ADD DL, 30h ; convert result to ASCII

JMP DISPLAY

CARRY_ADD:

ADD AL, 30h ; convert first digit to ASCII

MOV DL, '1' ; set carry flag

JMP DISPLAY

SUBTRACTION:

MOV AL, BL ; move first digit to AL

SUB AL, BH ; subtract third digit from AL

JC CARRY_SUB

MOV CL, DL ; move operator to CL

MOV AH, 2h ; display formula

INT 21h

MOV AH, 0 ; clear AH

MOV DL, AL ; move result to DL

ADD DL, 30h ; convert result to ASCII

JMP DISPLAY

CARRY_SUB:

SUB AL, 30h ; convert first digit to ASCII

MOV DL, '1' ; set carry flag

JMP DISPLAY

MULTIPLICATION:

MOV AX, BX ; move first digit to AX

MUL CH ; multiply fourth digit by AL

MOV CL, DL ; move low byte of result to CL

MOV AL, BL ; move second digit to AL

MUL BH ; multiply third digit by AL

ADD AX, CX ; add low byte of previous multiplication

MOV CL, DL ; move low byte of result to CL

MOV AH, 2h ; display formula

INT 21h

MOV AH, 0 ; clear AH

MOV DL, CL ; move low byte of result to DL

ADD DL, 30h ; convert result to ASCII

JMP DISPLAY

DIVISION:

MOV AL, BL ; move first digit to AL

MOV AH, 0 ; clear AH

DIV BH ; divide second digit by AL

MOV CL, AL ; move quotient to CL

MOV AL, BL ; move first digit to AL

MOV AH, 0 ; clear AH

MUL CL ; multiply first digit by quotient

MOV CL, DL ; move low byte of result to CL

SUB AH, AH ; clear AH

MOV DL, BH ; move third digit to DL

DIV CL ; divide third digit by low byte of result

MOV AH, 2h ; display formula

INT 21h

MOV AH,

```

Hope this helps! :^)

User WesleyE
by
8.4k points