Docsity

Programming details problem, Cheat Sheet of Computer Science

Partial preview of the text

Download Programming details problem and more Cheat Sheet Computer Science in PDF only on Docsity!

Lab 5

Submitted By: Soban Khan

Reg No: UW-22-AI-BS-0 52

Submitted To: Farhan Saleem

Course Title: COAL

COURSE CODE: CS-

PROGRAM 1:

Take two numbers from the user and display them on the screen.

Solution:

section .data prompt1 db 'Enter the first number: ', 0 prompt2 db 'Enter the second number: ', 0 output_format db 'You entered: %d and %d', 10, 0 section .bss num1 resd 1 num2 resd 1 section .text global _start _start: mov eax, 4 mov ebx, 1 mov ecx, prompt mov edx, 23 int 0x mov eax, 3 mov ebx, 0 mov ecx, num mov edx, 4 int 0x mov eax, 4

section .text global _start _start: mov eax, 4 mov ebx, 1 mov ecx, prompt mov edx, 16 int 0x mov eax, 3 mov ebx, 0 mov ecx, buffer mov edx, 255 int 0x mov eax, 0 mov edi, buffer count_characters: cmp byte [edi], 0 je end_count_characters inc eax inc edi jmp count_characters end_count_characters: mov eax, 4 mov ebx, 1 mov ecx, output_format mov edx, 32 int 0x

mov eax, 1 xor ebx, ebx int 0x

PROGRAM 3:

Prompt user to Enter an array of numbers and write the total number of

digits in that array on console.

Solution:

section .data prompt db 'Enter the size of the array: ', 0 array_prompt db 'Enter the elements of the array: ', 0 output_format db 'Total number of digits: %d', 10, 0 section .bss array_size resd 1 array resd 100 digit_count resd 1 section .text global _start _start: mov eax, 4 mov ebx, 1 mov ecx, prompt mov edx, 29 int 0x mov eax, 3 mov ebx, 0 mov ecx, array_size mov edx, 4 int 0x

mov eax, 1 xor ebx, ebx int 0x read_array: mov eax, 3 mov edx, ecx int 0x ret count_digits_in_number: mov ecx, 0 mov edi, 10 count_digits_in_number_loop: cmp ebx, 0 je end_count_digits_in_number mov eax, ebx xor edx, edx div edi inc ecx mov ebx, eax jmp count_digits_in_number_loop end_count_digits_in_number: mov [digit_count], ecx return

PROGRAM 4:

Prepare your CV

.model small .data nameMsg db 'Name: Sobankhan$' addressMsg db 'Address: c222, GulshaneAnwar$' cnicMsg db 'CNIC: 12345-6789012-3$' educationMsg db 'Education: B.Sc. in Computer Science$' phoneMsg db 'Phone Number: (555) 123-4567$' .code main proc mov ax, @data mov ds, ax call printText, offset nameMsg call printText, offset addressMsg call printText, offset cnicMsg call printText, offset educationMsg call printText, offset phoneMsg mov ah, 4Ch int 21h main endp printText proc mov ah, 9 int 21h ret