CS201 MID TERM SOLVED MCQs || PAST PAPERS || GROUP-1 || INTRODUCTION TO PROGRAMMING || VuTech Visit Website For More Solutions www.vutechofficial.blogspot.com …
CS401 ASSIGNMENT NO. 2 SPRING 2023 || 100% RIGHT SOLUTION || ASSEMBLY LANGUAGE PROGRAMMING || BY VuTech
Visit Website For More Solutions www.vutechofficial.blogspot.com
KINDLY, DON’T COPY PASTE
QUESTION-1
Write an assembly language program that performs following operations:
- Prints your name on the 1st row screen
- Prints your VUID on the 2nd row of screen
- If Right shift is pressed, it prints your VUID in the ascending order on the 3rd row of screen,
OR
If Left shift is pressed, it prints your VUID in the descending order on the 3rd row of screen,
Solution:
; Data segment
section .data
name db 'Your Name', 0
vuid db 'Your VUID', 0
shift_msg db 'Shift:', 0
asc_msg db 'VUID SORTED : ', 0
desc_msg db 'VUID SORTED : ', 0
; Text segment
section .text
global _start
_start:
; Print name on the 1st row
mov edx, 1
mov ecx, name
mov ebx, 1
mov eax, 4
int 0x80
; Print VUID on the 2nd row
mov edx, 1
mov ecx, vuid
mov ebx, 1
mov eax, 4
int 0x80
; Check if Right shift is pressed
mov eax, 0x80
mov ebx, 0
int 0x16
cmp ah, 0x2a ; Right shift key code
jne check_left_shift
; Print ascending order on the 3rd row
mov edx, 1
mov ecx, asc_msg
mov ebx, 1
mov eax, 4
int 0x80
; Right shift is pressed, print VUID in ascending order
mov edi, 1 ; Start at 1
mov esi, 9 ; End at 9
ascending_loop:
mov eax, edi
add eax, '0'
mov [esp], eax ; Store digit in the stack
mov edx, 1
mov ecx, esp
mov ebx, 1
mov eax, 4
int 0x80
inc edi
cmp edi, esi
jle ascending_loop
jmp end_program
check_left_shift:
; Check if Left shift is pressed
mov eax, 0x80
mov ebx, 0
int 0x16
cmp ah, 0x36 ; Left shift key code
jne end_program
; Print descending order on the 3rd row
mov edx, 1
mov ecx, desc_msg
mov ebx, 1
mov eax, 4
int 0x80
; Left shift is pressed, print VUID in descending order
mov edi, 9 ; Start at 9
mov esi, 1 ; End at 1
descending_loop:
mov eax, edi
add eax, '0'
mov [esp], eax ; Store digit in the stack
mov edx, 1
mov ecx, esp
mov ebx, 1
mov eax, 4
int 0x80
dec edi
cmp edi, esi
jge descending_loop
end_program:
; Exit the program
mov eax, 1
xor ebx, ebx
int 0x80
KINDLY, DON’T COPY PASTE SUBSCRIBE, SHARE, LIKE AND COMMENTS FOR MORE UPDATES SEND WHATSAPP OR E-MAIL FOR ANY QUERY 0325-6644800 kamranhameedvu@gmail.com Visit Website For More Solutions www.vutechofficial.blogspot.com
We provide Virtual University of Pakistan Study Materials such as Solution of Assignments, GDBs, Mid Term Solved Papers, Final Term Solved Papers, Mid Term Solved MCQs, and Final Term Solved MCQs. We also provide regular Semester Quizzes, Updated Handouts, and Short Questions and Answers. We help you with your research and many other educational-related topics, as far as we know. Furthermore, Share your problem with us and Please feel free to ask any related questions.