Class Task 8: Computer Organization and Assembly Language

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

Class Task 8

Computer Organization and Assembly Language

COAL-255

Submitted To

Mr. Muhammad Jabbar

Submitted By

Muhammad Uzair Zafar

Roll Number

21011519-051

Section

Department of Computer Science


University of Gujrat, Hafiz Hayat Campus
Class Task 8: Computer Organization and Assembly Language

Task 1
Code Snip:

Output Snip:

Explanation:
This program is repeating a string up to 10 times by calling the label repeat 10 times with the help of
loop. At initial state we are declaring a string str1 such as “Welcome UZAIR” after that we are assigning a
value 10 to counter register and the end of main block. We are looping the repeat label. It will execute
until the counter register value comes to 0. The word 0ah with string str is used to break the line in
console every time when the string str is called.

Submitted By: 21011519-051 Page 2 of 11


Class Task 8: Computer Organization and Assembly Language

Task 2
Code Snip:

Submitted By: 21011519-051 Page 3 of 11


Class Task 8: Computer Organization and Assembly Language

Output:

Explanation:
In this program we are displaying the even number in a user defined range. For that purpose we have
taken to three strings, one string to display the starting value to enter and second for taking ending value
and third one is for showing result. And then subtracting the ending value from starting value to
understand how many times the loop executed and then assigning the value to counter register suppose
starting is 2 and ending is 10 so 10-2=8 so loop called for 8 times Logic: we know that the number is
even if it is divisble by 2 so for that purpose we are dividing the current value which is stored in edi and
moving into eax with ebx which has value 2. After that we are comparing the edx value because the
remainder should be store in it, if it is equal to 0 so it jump to labal L1: to show the value and if the
remainder is not equal to 0 then it move to label notEven where it incrementing the edi value and again
loop incremented and goes back to label l1, this process continues until the counter value became Zero.

Submitted By: 21011519-051 Page 4 of 11


Class Task 8: Computer Organization and Assembly Language

Task 3
Code Snip:

Output Snip:

Explanation:
This is simple a looping program with addition. In this program we are assigning the value 10 to counter
register which means we are looping the statement up to 10 times. Before the start of repeat label we
are setting the eax to 0. In the repeat loop we are adding 2 in eax with its previous value and calling the
eax to show his latest value. The output would be in + it is because we are calling the eax with statement
call writeint. If we call it with write dec then we don’t get a + sign with the output. This should be
continued until ecx register value became 0.

Submitted By: 21011519-051 Page 5 of 11


Class Task 8: Computer Organization and Assembly Language

Task 4
Code Snip:

Output Snip:

Explanation:
This program is same as even but in this program we are displaying the odd values with in a range from 1
to 20. In this program we have assign the counter register value to 20 so loop continues for twenty
times. In label repeat1 we are moving the ebx=1 value to eax after that we are dividing the eax by 2 we
know that by dividing the quotient values goes to eax and remainder values goes to edx. After dividing
we are comparing the edx value to 0. If edx value is not zero then we are moving to label L1 and
displaying the result because odd numbers are those which are not divisible by 2. And if edx value would

Submitted By: 21011519-051 Page 6 of 11


Class Task 8: Computer Organization and Assembly Language

be equal to 0 then we are jumping to label evn where we increment the ebx value and loop value jump
to next and this process continues upto 20 times until counter register set to zero.

Submitted By: 21011519-051 Page 7 of 11


Class Task 8: Computer Organization and Assembly Language

Task 5
Code Snip:

Output Snip:

Explanation:
This program is displaying the table of specific value. In output I have displayed the table of 3 up to
3*10=30 . At the start we are assigning the value 10 to counter register and times to edi register. After
that we are repeating the label repeat upto 10 times. In label we are moving the edi value to eax and
then multiplying it to ebx because it contains the value 3 as soon as the loop incremented means second

Submitted By: 21011519-051 Page 8 of 11


Class Task 8: Computer Organization and Assembly Language

loop started we are incrementing the edi and again assigning edi value to edi. Which means in second
loop 3*2 =6 and this process could be executed until the counter register value comes to zero. Two string
are used to show the output as 3*1=3 upto 3*10=30. This program doesn’t take any input from user to
display the result.

Submitted By: 21011519-051 Page 9 of 11


Class Task 8: Computer Organization and Assembly Language

Task 6
Code Snip:

Output Snip:

Submitted By: 21011519-051 Page 10 of 11


Class Task 8: Computer Organization and Assembly Language

Explanation:
This is the same program as the previous one but only the difference is that in this program we are
taking the value value from user to display user defined table. Same the procedure is performed in
previous task we are defining the ebx value from programming side but in this case we are taking the
value from user which would be stored in eax and after taking the value we are moving the eax value to
ebx and same label repeat looped up to 10 times until the counter register value set to zero.

Submitted By: 21011519-051 Page 11 of 11

You might also like