Question
Assembly language.   



Can u pls send me a copyable code please. If you can run it.
X86. Asm.   
Subject: Assembly language If you know x86 asm then only answer it Use x86 asm version send me a written code please send me with out put please send me a copyable code i promise to give you thumbs up, question: Implement a simple 4 functios calculator for 3 digits entry. The user will enter 2 digits for the first and the second numbers. The user will chose between the operation type or The result will be displayed. Work with 32 bits variables and register.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

SE emulator screen (80x25 chars) note: calculator works with integer values only enter first number: clear Screen change font

name "calcBebo"

PUTC MACRO char
PUSH AX
MOV AL, char
MOV AH, 0Eh
INT 10h   
POP AX
ENDM
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

org 100h

jmp start


; define variables:

msg0 db "note: calculator works with integer values only.",0Dh,0Ah,'$'
msg1 db 0Dh,0Ah, 0Dh,0Ah, 'enter first number: $'
msg2 db "enter the operator: + - * / : $"
msg3 db "enter second number: $"
msg4 db 0dh,0ah , 'the approximate result of my calculations is : $'
msg5 db 0dh,0ah ,'thank you for using the calculator! press any key... ', 0Dh,0Ah, '$'
err1 db "wrong operator!", 0Dh,0Ah , '$'
smth db " and something.... $"

; operator can be: '+','-','*','/' or 'q' to exit in the middle.
opr db '?'

; first and second number:
num1 dw ?
num2 dw ?


start:
mov dx, offset msg0
mov ah, 9
int 21h


lea dx, msg1
mov ah, 09h ; output string at ds:dx
int 21h


call scan_num

; store first number:
mov num1, cx

; new line:
putc 0Dh
putc 0Ah


lea dx, msg2
mov ah, 09h ; output string at ds:dx
int 21h


; get operator:
mov ah, 1 ; single char input to AL.
int 21h
mov opr, al

putc 0Dh
putc 0Ah


cmp opr, 'q' ; q - exit in the middle.
je exit

cmp opr, '*'
jb wrong_opr
cmp opr, '/'
ja wrong_opr


lea dx, msg3
mov ah, 09h
int 21h

call scan_num

mov num2, cx


lea dx, msg4
mov ah, 09h ; output string at ds:dx
int 21h


cmp opr, '+'
je do_plus

cmp opr, '-'
je do_minus

cmp opr, '*'
je do_mult

cmp opr, '/'
je do_div

wrong_opr:
lea dx, err1
mov ah, 09h ; output string at ds:dx
int 21h


exit:

lea dx, msg5
mov ah, 09h
int 21h

mov ah, 0
int 16h


ret ; return back to os.
do_plus:


mov ax, num1
add ax, num2
call print_num ; print ax value.

jmp exit

do_minus:

mov ax, num1
sub ax, num2
call print_num ; print ax value.

jmp exit


do_mult:

mov ax, num1
imul num2 ; (dx ax) = ax * num2.
call print_num ; print ax value.

jmp exit


do_div:

mov dx, 0
mov ax, num1
idiv num2 ; ax = (dx ax) / num2.
cmp dx, 0
jnz approx
call print_num ; print ax value.
jmp exit
approx:
call print_num ; print ax value.
lea dx, smth
mov ah, 09h ; output string at ds:dx
int 21h
jmp exit

SCAN_NUM PROC NEAR
PUSH DX
PUSH AX
PUSH SI
  
MOV CX, 0

; reset flag:
MOV CS:make_minus, 0

next_digit:

; get char from keyboard
; into AL:
MOV AH, 00h
INT 16h
; and print it:
MOV AH, 0Eh
INT 10h

; check for MINUS:
CMP AL, '-'
JE set_minus

; check for ENTER key:
CMP AL, 0Dh ; carriage return?
JNE not_cr
JMP stop_input
not_cr:


CMP AL, 8 ; 'BACKSPACE' pressed?
JNE backspace_checked
MOV DX, 0 ; remove last digit by
MOV AX, CX ; division:
DIV CS:ten ; AX = DX:AX / 10 (DX-rem).
MOV CX, AX
PUTC ' ' ; clear position.
PUTC 8 ; backspace again.
JMP next_digit
backspace_checked:


; allow only digits:
CMP AL, '0'
JAE ok_AE_0
JMP remove_not_digit
ok_AE_0:
CMP AL, '9'
JBE ok_digit
remove_not_digit:   
PUTC 8 ; backspace.
PUTC ' ' ; clear last entered not digit.
PUTC 8 ; backspace again.
JMP next_digit ; wait for next input.   
ok_digit:


; multiply CX by 10 (first time the result is zero)
PUSH AX
MOV AX, CX
MUL CS:ten ; DX:AX = AX*10
MOV CX, AX
POP AX

; check if the number is too big
; (result should be 16 bits)
CMP DX, 0
JNE too_big

; convert from ASCII code:
SUB AL, 30h

; add AL to CX:
MOV AH, 0
MOV DX, CX ; backup, in case the result will be too big.
ADD CX, AX
JC too_big2 ; jump if the number is too big.

JMP next_digit

set_minus:
MOV CS:make_minus, 1
JMP next_digit

too_big2:
MOV CX, DX ; restore the backuped value before add.
MOV DX, 0 ; DX was zero before backup!
too_big:
MOV AX, CX
DIV CS:ten ; reverse last DX:AX = AX*10, make AX = DX:AX / 10
MOV CX, AX
PUTC 8 ; backspace.
PUTC ' ' ; clear last entered digit.
PUTC 8 ; backspace again.
JMP next_digit ; wait for Enter/Backspace.
  
  
stop_input:
; check flag:
CMP CS:make_minus, 0
JE not_minus
NEG CX
not_minus:

POP SI
POP AX
POP DX
RET
make_minus DB ? ; used as a flag.
SCAN_NUM ENDP

PRINT_NUM PROC NEAR
PUSH DX
PUSH AX

CMP AX, 0
JNZ not_zero

PUTC '0'
JMP printed

not_zero:
; the check SIGN of AX,
; make absolute if it's negative:
CMP AX, 0
JNS positive
NEG AX

PUTC '-'

positive:
CALL PRINT_NUM_UNS
printed:
POP AX
POP DX
RET
PRINT_NUM ENDP


PRINT_NUM_UNS PROC NEAR
PUSH AX
PUSH BX
PUSH CX
PUSH DX

; flag to prevent printing zeros before number:
MOV CX, 1

; (result of "/ 10000" is always less or equal to 9).
MOV BX, 10000 ; 2710h - divider.

; AX is zero?
CMP AX, 0
JZ print_zero

begin_print:

; check divider (if zero go to end_print):
CMP BX,0
JZ end_print

; avoid printing zeros before number:
CMP CX, 0
JE calc
; if AX<BX then result of DIV will be zero:
CMP AX, BX
JB skip
calc:
MOV CX, 0 ; set flag.

MOV DX, 0
DIV BX ; AX = DX:AX / BX (DX=remainder).

; print last digit
; AH is always ZERO, so it's ignored
ADD AL, 30h ; convert to ASCII code.
PUTC AL


MOV AX, DX ; get remainder from last div.

skip:
; calculate BX=BX/10
PUSH AX
MOV DX, 0
MOV AX, BX
DIV CS:ten ; AX = DX:AX / 10 (DX=remainder).
MOV BX, AX
POP AX

JMP begin_print
  
print_zero:
PUTC '0'
  
end_print:

POP DX
POP CX
POP BX
POP AX
RET
PRINT_NUM_UNS ENDP

ten DW 10 ; used as multiplier/divider by SCAN_NUM & PRINT_NUM_UNS.

GET_STRING PROC NEAR
PUSH AX
PUSH CX
PUSH DI
PUSH DX

MOV CX, 0 ; char counter.

CMP DX, 1 ; buffer too small?
JBE empty_buffer ;

DEC DX ; reserve space for last zero.

wait_for_key:

MOV AH, 0 ; get pressed key.
INT 16h

CMP AL, 0Dh ; 'RETURN' pressed?
JZ exit_GET_STRING


CMP AL, 8 ; 'BACKSPACE' pressed?
JNE add_to_buffer
JCXZ wait_for_key ; nothing to remove!
DEC CX
DEC DI
PUTC 8 ; backspace.
PUTC ' ' ; clear position.
PUTC 8 ; backspace again.
JMP wait_for_key

add_to_buffer:

CMP CX, DX ; buffer is full?
JAE wait_for_key ; if so wait for 'BACKSPACE' or 'RETURN'...

MOV [DI], AL
INC DI
INC CX
  
; print the key:
MOV AH, 0Eh
INT 10h

JMP wait_for_key

exit_GET_STRING:

MOV [DI], 0

empty_buffer:

POP DX
POP DI
POP CX
POP AX
RET
GET_STRING ENDP

S emulator screen (80x25 chars) note: calculator works with integer values only. enter first number 20 enter the operator: en

56 emulator screen (80x25 chars) note: calculator works with integer values only. enter first number 20 enter the operator: +

SE emulator screen (80x25 chars) note: calculator works with integer values only. enter first number: 20 enter the operator:

SEh emulator screen (80x25 chars) note calculator works with integer values only. enter first number 20 enter the operator: e

Add a comment
Know the answer?
Add Answer to:
Assembly language.    Can u pls send me a copyable code please. If you can run...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • How to write assembly language for x86 and where do I put the code under as? please give me answe...

    how to write assembly language for x86 and where do I put the code under as? please give me answer as soon as possible. ZOOMt COSC 2325.S01 Kxtra Credit l'rogram Problem: Starting wilh the following C+program #includes iostream > using cspace sld; cxlem'C" long Average (long, long LD; void main long Arrayl Г 101-1, 2, 3. 4, 5, 6, 7, 8. 9. 103; long Aray2 111」 {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; coul <'': "Average...

  • assembly language class I have some confusing can you answer me a couple question? What are...

    assembly language class I have some confusing can you answer me a couple question? What are the basic types of data? How many bits does each on us? Know the basics of moving data from memory to registers? What happens in the registers when data is moved/added? thank you

  • Can someone do this in assembly code for me please Given the following input and output, write ...

    can someone do this in assembly code for me please Given the following input and output, write the assembly code necessary to make it look exactly the same as below. Pay careful attention to spacing and blank lines: Input Enter a number: 1 Enter a larger number: 3 Enter an even larger number: 5 Output 1 < 3 < 5 5 > 3 > 1 aseembly programing language

  • MIPS ASSEMBLY PROGRAM: PLEASE Write in MIPS Assembly language. Take strings as input and calculate and...

    MIPS ASSEMBLY PROGRAM: PLEASE Write in MIPS Assembly language. Take strings as input and calculate and print a simple checksum for each string. Make your string long enough to hold 50 characters. Don't forget to leave space for the null byte. Our checksum algorithm will produce a value which you can print with the syscall for printing a character. Stop reading strings when the user enters ".". The syscall to read a string (sycall code 8) adds a newline to...

  • THIS IS IN THE JAVA SCRIPT CODE ALSO PLEASE SEND ME THE CODE TYPED THANK YOU....

    THIS IS IN THE JAVA SCRIPT CODE ALSO PLEASE SEND ME THE CODE TYPED THANK YOU. Program 1 Write an inheritance hierarchy of three-dimensional shapes. Make a top-level shape interface that has methods for getting information such as the volume and the surface area of a three-dimensional shape. Then make classes and subclasses that implement various shapes such as cube, cylinders and spheres. Place common behavior in superclasses whenever possible, and use abstract classes as appropriate. Add methods to the...

  • Can someone complete this program for me in c programming language? Thank you! The Send-Ex Shipping...

    Can someone complete this program for me in c programming language? Thank you! The Send-Ex Shipping Company charges the following rates: Weight of Package 2 lbs or less Over 2 lbs but no more than 6 lbs Over 6 lbs but no more than 10 lbs Over 10 lbs Rate per Pound $1.10 $2.20 $3.70 $4.10 Write a program that asks the user to enter the weight of a package and then displays the total shipping charge. Reserve Point Opportunity/...

  • Can you show me a Flappy Bird game's code running in Visual Studio 2015 (The language...

    Can you show me a Flappy Bird game's code running in Visual Studio 2015 (The language is C++), please?

  • This is Assembly Language...please i want you to give proper documentation or comment of every code...

    This is Assembly Language...please i want you to give proper documentation or comment of every code you write, so i can understand your code. Thank you! ** 2. Exchanging Pairs of Array Values Write a program with a loop and indexed addressing that exchanges every pair of values in an array with an even number of elements. Therefore, item i will exchange with item i+1, and item i+2 will exchange with item i+3, and so on.

  • can somone pls correct me or give more opinion is right please it's important I don't...

    can somone pls correct me or give more opinion is right please it's important I don't need anything copy from the Internet thank you The Dental Hygiene program requires that you complete an essay with your application. Please write 3 to 4 sentences on why you chose I choose a dental hygiene program to educates everyone about their oral hygiene, and I want to become dental hygiene to help everyone to keep their smiles for a lifetime, I choose this...

  • Please write the code in assembly language which can run in HLA. Thank you very much!!...

    Please write the code in assembly language which can run in HLA. Thank you very much!! -So we need to write the code in assembly language in Notepad++, end with .hla and run it in CMD. - This project is about writing a program to read numbers, counts the items read, calculates the total, the maximum and minimum of the numbers. -The program stops when a 0 is entered. Zero will not be part of the data. -work with integers,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT