Question

3. Write a program in assembly language that reads a number from the keyboard and displays...

3. Write a program in assembly language that reads a number from the keyboard and displays it on the screen.

4. Write a program in assembly language to ask two digits from the user, store the digits in the EAX and EBX register, respectively, add the values, store the result in a memory location 'res' and finally display the result.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

3)

section .text

global _start

_start:

mov ecx, msg
mov edx, msg_len
mov ebx, 1
mov eax, 4
int 0x80
  
mov eax,3
mov ebx,0
mov ecx,sum
int 80h

mov ecx, res_prompt
mov edx, res_len
mov ebx, 1
mov eax, 4
int 0x80

mov ecx, sum
mov edx, 2
mov ebx, 1
mov eax, 4
int 0x80

mov eax, 1
int 0x80

section .data
msg db "Enter a number ", 0xA
msg_len equ $ - msg

res_prompt db "The input number is "
res_len equ $ - res_prompt

segment .bss
sum resb 2


Output :-

4)

section .text

global _start

_start:

mov ecx, msg
mov edx, msg_len
mov ebx, 1
mov eax, 4
int 0x80
  
mov eax,3
mov ebx,0   
mov ecx,dig_1
mov edx,2
int 80h

mov ecx, msg
mov edx, msg_len
mov ebx, 1
mov eax, 4
int 0x80
  
mov eax,3
mov ebx,0   
mov ecx,dig_2
mov edx,2
int 80h

mov ecx, res_prompt
mov edx, res_len
mov ebx, 1
mov eax, 4
int 0x80

mov eax, [dig_1]
sub eax, '0'
mov ebx, [dig_2]
sub ebx, '0'

add eax, ebx
add eax, '0'

mov [res],eax

mov ecx, res
mov edx, 1
mov ebx, 1
mov eax, 4
int 0x80

mov eax, 1
int 0x80

section .data
msg db "Enter a digit ", 0xA,0xD
msg_len equ $ - msg

res_prompt db "The sum of two digits is "
res_len equ $ - res_prompt

segment .bss
dig_1 resb 2
dig_2 resb 2
res resb 1

Output :-

Add a comment
Know the answer?
Add Answer to:
3. Write a program in assembly language that reads a number from the keyboard and displays...
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
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