Practical 1: Language Programs Which Prints "Hello World" On Screen
Practical 1: Language Programs Which Prints "Hello World" On Screen
Practical 1: Language Programs Which Prints "Hello World" On Screen
Practical 1
Aim: Introduction to 8086 Microprocessor & Assembly Language Programming. Write an assembly
language programs which prints "Hello World" on screen.
Hardware: PC
Implementation:
name "hi-world"
org 100h
1
CE341: Microprocessor Architectures and Assembly Programming 16CE068
ret
Output:
2
CE341: Microprocessor Architectures and Assembly Programming 16CE068
Practical 2
Aim:
Program-1: Change the Foreground color of each letter of "Hello world"
Hardware: PC
Implementation :
name "hi-world"
org 100h
3
CE341: Microprocessor Architectures and Assembly Programming 16CE068
mov ds, ax
4
CE341: Microprocessor Architectures and Assembly Programming 16CE068
ret
Output:
Implementation:
name "hi-world"
5
CE341: Microprocessor Architectures and Assembly Programming 16CE068
;
;0 0000 black
;1 0001 blue
;2 0010 green
;3 0011 cyan
;4 0100 red
;5 0101 magenta
;6 0110 brown
;7 0111 light gray
;8 1000 dark gray
;9 1001 light blue
;a 1010 light green
;b 1011 light cyan
;c 1100 light red
;d 1101 light magenta
;e 1110 yellow
;f 1111 white
org 100h
6
CE341: Microprocessor Architectures and Assembly Programming 16CE068
7
CE341: Microprocessor Architectures and Assembly Programming 16CE068
int 16h
ret
Output:
8
CE341: Microprocessor Architectures and Assembly Programming 16CE068
Practical 3
Aim:
Program-1: Write a program to perform addition of 5 elements. Elements are 5,4,5,2,1
Hardware: PC
Implementation:
name "calc-sum"
; number of elements:
mov cx, 5
; bx is an index:
mov bx, 0
; sum elements:
next: add al, vector[bx]
; next byte:
inc bx
; store result in m:
mov m, al
9
CE341: Microprocessor Architectures and Assembly Programming 16CE068
ret
; variables:
vector db 5, 4, 5, 2, 1
m db 0
print_al proc
cmp al, 0
jne print_al_r
push ax
mov al, '0'
mov ah, 0eh
int 10h
pop ax
ret
print_al_r:
pusha
mov ah, 0
cmp ax, 0
je pn_done
mov dl, 10
div dl
call print_al_r
mov al, ah
add al, 30h
mov ah, 0eh
int 10h
jmp pn_done
pn_done:
popa
ret
endp
10
CE341: Microprocessor Architectures and Assembly Programming 16CE068
Output:
Implementation:
name "calc-sum"
; number of elements:
mov cx, 20
; bx is an index:
mov bx, 0
; sum elements:
next: add al, vector[bx]
; next byte:
inc bx
; store result in m:
mov m, al
11
CE341: Microprocessor Architectures and Assembly Programming 16CE068
int 21h
ret
; variables:
vector db 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
m db 0
print_al proc
cmp al, 0
jne print_al_r
push ax
mov al, '0'
mov ah, 0eh
int 10h
pop ax
ret
print_al_r:
pusha
mov ah, 0
cmp ax, 0
je pn_done
mov dl, 10
div dl
call print_al_r
mov al, ah
add al, 30h
mov ah, 0eh
int 10h
jmp pn_done
pn_done:
popa
ret
endp
12
CE341: Microprocessor Architectures and Assembly Programming 16CE068
Output:
13
CE341: Microprocessor Architectures and Assembly Programming 16CE068
Practical 4
Aim: Observe the values of flags for Example program: Compare Numbers. Write down
Arithmetic and Logic Instructions from Tutorial.
Hardware: PC
Implementation:
name "flags"
org 100h
; (signed/unsigned)
; 4 is equal to 4
mov ah, 4
mov al, 4
cmp ah, al
nop
; (signed/unsigned)
; 4 is above and greater then 3
mov ah, 4
mov al, 3
cmp ah, al
nop
; -5 = 251 = 0fbh
; (signed)
; 1 is greater then -5
mov ah, 1
mov al, -5
cmp ah, al
nop
; (unsigned)
; 1 is below 251
mov ah, 1
mov al, 251
cmp ah, al
nop
14
CE341: Microprocessor Architectures and Assembly Programming 16CE068
; (signed)
; -3 is less then -2
mov ah, -3
mov al, -2
cmp ah, al
nop
; (signed)
; -2 is greater then -3
mov ah, -2
mov al, -3
cmp ah, al
nop
; (unsigned)
; 255 is above 1
mov ah, 255
mov al, 1
cmp ah, al
nop
15
CE341: Microprocessor Architectures and Assembly Programming 16CE068
Output:
Program-3: Rewrite program to compare alphabet a to z. l act as a eqator. it prints above and below
with respect to l.
Implementation:
name "flags"
org 100h
; (signed/unsigned)
; 4 is equal to 4
mov ah, 4
mov al, 4
cmp ah, al
nop
; (signed/unsigned)
; 4 is above and greater then 3
mov ah, 4
mov al, 3
cmp ah, al
nop
; -5 = 251 = 0fbh
; (signed)
; 1 is greater then -5
mov ah, 1
mov al, -5
cmp ah, al
nop
; (unsigned)
; 1 is below 251
16
CE341: Microprocessor Architectures and Assembly Programming 16CE068
mov ah, 1
mov al, 251
cmp ah, al
nop
; (signed)
; -3 is less then -2
mov ah, -3
mov al, -2
cmp ah, al
nop
; (signed)
; -2 is greater then -3
mov ah, -2
mov al, -3
cmp ah, al
nop
; (unsigned)
; 255 is above 1
mov ah, 255
mov al, 1
cmp ah, al
nop
17
CE341: Microprocessor Architectures and Assembly Programming 16CE068
Output:
18
CE341: Microprocessor Architectures and Assembly Programming 16CE068
Practical 5
Aim: AIM: 8086 Procedures and dealy.
Program-1: Traffic control System. Review program of traffic control system available in simulator.
Hardware: PC
Implementation:
#start=Traffic_Lights.exe#
name "traffic"
next:
mov ax, [si]
out 4, ax
; FEDC_BA98_7654_3210
situation dw 0000_0011_0000_1100b
s1 dw 0000_0110_1001_1010b
s2 dw 0000_1000_0110_0001b
s3 dw 0000_1000_0110_0001b
s4 dw 0000_0100_1101_0011b
sit_end = $
19
CE341: Microprocessor Architectures and Assembly Programming 16CE068
Output:
Implementation:
#start=Traffic_Lights.exe#
name "traffic"
next:
mov ax, [si]
out 4, ax
20
CE341: Microprocessor Architectures and Assembly Programming 16CE068
; FEDC_BA98_7654_3210
situation dw 0000_0011_0000_1100b
s1 dw 0000_0110_1001_1010b
s2 dw 0000_1000_0110_0001b
s3 dw 0000_1000_0110_0001b
s4 dw 0000_0100_1101_0011b
sit_end = $
#start=Traffic_Lights.exe#
name "traffic"
next:
mov ax, [si]
out 4, ax
ret
m1 ENDP
CALL m1
add si, 2 ; next situation
cmp si, sit_end
jb next
mov si, offset situation
jmp next
; FEDC_BA98_7654_3210
situation dw 0000_0011_0000_1100b
s1 dw 0000_0110_1001_1010b
s2 dw 0000_1000_0110_0001b
s3 dw 0000_1000_0110_0001b
s4 dw 0000_0100_1101_0011b
21
CE341: Microprocessor Architectures and Assembly Programming 16CE068
sit_end = $
Output:
22
CE341: Microprocessor Architectures and Assembly Programming 16CE068
Practical 6
Aim:
Hardware: PC
Implementation:
; reverse string
name "reverse"
org 100h
jmp start
mov si, bx
found_the_end: dec si
; do the swapping:
mov [si], al
mov [bx], ah
inc bx
dec si
jmp do_reverse
23
CE341: Microprocessor Architectures and Assembly Programming 16CE068
int 21h
ret
Output:
Implementation:
name "pali"
org 100h
jmp start
m1:
s db 'able was ere ere saw elba'
s_size = $ - m1
db 0Dh,0Ah,'$'
start:
lea di, s
mov si, di
add si, s_size
dec si ; point to last char!
24
CE341: Microprocessor Architectures and Assembly Programming 16CE068
next_char:
mov al, [di]
mov bl, [si]
cmp al, bl
jne not_palindrome
inc di
dec si
loop next_char
is_palindrome:
; the string is "palindrome!"
mov ah, 9
mov dx, offset msg1
int 21h
jmp stop
not_palindrome:
; the string is "not palindrome!"
mov ah, 9
mov dx, offset msg2
int 21h
stop:
ret
Output:
25
CE341: Microprocessor Architectures and Assembly Programming 16CE068
Program-3: Write an assembly program which converts upped case to lower and vice versa for a
given string.
Implementation:
name "upper"
org 100h
jmp start
start:
mov bx, dx
mov ah, 0
mov al, ds:[bx+1]
add bx, ax ; point to end of string.
mov ch, 0
mov cl, [bx+1] ; get string size.
26
CE341: Microprocessor Architectures and Assembly Programming 16CE068
upper_case:
; convert to uppercase:
ok:
inc bx ; next char.
loop upper_case
null:
ret ; return to operating system.
Output:
27
CE341: Microprocessor Architectures and Assembly Programming 16CE068
Practical 7
Aim:
Program-1:Write an assembly program which pritns ASCII value of given string letters on LED display.
(Dealy between each letter must be 2 sec)
Implementation:
#start=led_display.exe#
name "paliled"
org 100h
jmp start
m1:
s db 'abcdef'
s_size = $ - m1
db 0Dh,0Ah,'$'
start:
mov ah, 9
mov dx, offset s
int 21h
lea di, s
mov ax, 0
next_char:
mov al, [di]
out 199,ax
inc di
loop next_char
ret
28
CE341: Microprocessor Architectures and Assembly Programming 16CE068
Output:
Program-2:Write an assembly program which rotates stepper moter in clock wise direction. (Delay between
each roatation must be 1 sec)
Implementation:
#start=stepper_motor.exe#
name "stepper"
#make_bin#
jmp start
29
CE341: Microprocessor Architectures and Assembly Programming 16CE068
start:
mov bx, offset datcw ; start from clock-wise half-step.
mov si, 0
mov cx, 0 ; step counter
next_step:
; motor sets top bit when it's ready to accept new command
wait: in al, 7
test al, 10000000b
jz wait
inc si
cmp si, 4
jb next_step
mov si, 0
inc cx
cmp cx, steps_before_direction_change
jb next_step
mov cx, 0
add bx, 4 ; next bin data
jmp next_step
30
CE341: Microprocessor Architectures and Assembly Programming 16CE068
Output:
Implementation:
name "keycount"
org 100h
jmp wait
mov ax, bx
31
CE341: Microprocessor Architectures and Assembly Programming 16CE068
call print_ax
msg db "I'll count all your keypresses. press 'Esc' to stop...", 0Dh,0Ah, "$"
msg2 db 0Dh,0Ah, "recorded keypresses: $"
Output:
32
CE341: Microprocessor Architectures and Assembly Programming 16CE068
Practical 8
Aim:
Program-1: Write an assembly program which gets the number from the user and calculates factorial
for it.
Implementation:
org 100h
mov ax,05h
mov bx,04h
mov cx,01h
loop:
mul cx
inc cx
sub bx,01h
cmp bx,00h
jnz loop
ret
Output:
33
CE341: Microprocessor Architectures and Assembly Programming 16CE068
Program-2:Write an assembly program which converts a 2 digit hexadecimal number into binary.
Implementation:
; hex convertor.
; this example converts a 2 digit hexadecimal number
; into a numeric value and then into decimal/ascii string representation,
; and finally it prints out the result in binary code.
name "hex"
org 100h
jmp start
start:
; convert first digit to value 0..15 from ascii:
mov al, source[0]
cmp al, '0'
jae f1
f1:
cmp al, '9'
ja f2 ; jumps only if not '0' to '9'.
f2:
; gets here if it's 'a' to 'f' case:
or al, 00100000b ; remove upper case (if any).
sub al, 57h ; convert char 'a' to 'f' to numeric value.
num1_ready:
mov bl, 16
mul bl ; ax = al * bl
mov temp, ax
34
CE341: Microprocessor Architectures and Assembly Programming 16CE068
g1:
cmp al, '9'
ja g2 ; jumps only if not '0' to '9'.
g2:
; gets here if it's 'a' to 'f' case:
or al, 00100000b ; remove upper case (if any).
sub al, 57h ; convert char 'a' to 'f' to numeric value.
num2_ready:
xor ah, ah
add temp, ax
; convertion from hex string complete!
push temp ; store original temp value.
next_digit:
cmp temp, 0
je stop
xor ah, ah
mov temp, ax
stop:
pop temp ; re-store original temp value.
35
CE341: Microprocessor Architectures and Assembly Programming 16CE068
Output:
36
CE341: Microprocessor Architectures and Assembly Programming 16CE068
Practical 10
Aim: Multicore programming, L1, L2 and L3 cache rebuilt and performance measurement.
Comparison between Intel and AMD architecture.
Caching was invented to solve a significant problem. In the early decades of computing, main memory
was extremely slow and incredibly expensive — but CPUs weren’t particularly fast, either. Starting in the
1980s, the gap began to widen quickly. Microprocessor clock speeds took off, but memory access times
improved far less dramatically. As this gap grew, it became increasingly clear that a new type of fast
memory was needed to bridge the gap.
How caching works: CPU caches are small pools of memory that store information the CPU is most likely
to need next. Which information is loaded into cache depends on sophisticated algorithms and certain
assumptions about programming code. The goal of the cache system is to ensure that the CPU has the next
bit of data it will need already loaded into cache by the time it goes looking for it (also called a cache hit).
A cache miss, on the other hand, means the CPU has to go scampering off to find the data elsewhere. This
is where the L2 cache comes into play — while it’s slower, it’s also much larger. Some processors use an
inclusive cache design (meaning data stored in the L1 cache is also duplicated in the L2 cache) while
others are exclusive (meaning the two caches never share data). If data can’t be
found in the L2 cache, the CPU continues down the chain to L3 (typically still on-die), then L4 (if it exists)
and main memory (DRAM).
37
CE341: Microprocessor Architectures and Assembly Programming 16CE068
This chart shows the relationship between an L1 cache with a constant hit rate, and a larger L2 cache. Note that
the total hit rate goes up sharply as the size of the L2 increases. A larger, slower, cheaper L2 can provide all
the benefits of a large L1 — but without the die size and power consumption penalty. Most modern L1 cache
rates have hit rates far above the theoretical 50 percent shown here — Intel and AMD both typically field
cache hit rates of 95 percent or higher.
Multicore Programming:
In a multiprogramming system there are one or more programs loaded in main memory which are ready to
execute. Only one program at a time is able to get the CPU for executing its instructions (i.e., there is at most
one process running on the system) while all the others are waiting their turn. The main idea of
multiprogramming is to maximize the use of CPU time. Indeed, suppose the currently running process is
performing an I/O task (which, by definition, does not need the CPU to be accomplished). Then, the OS may
interrupt that process and give the control to one of the other in-main-memory programs that are ready to
execute (i.e. process context switching). In this way, no CPU time is wasted by the system waiting for the I/O
task to be completed, and a running process keeps executing until either it voluntarily releases the CPU or
when it blocks for an I/O operation. Therefore, the ultimate goal of multiprogramming is to keep the CPU busy
as long as there are processes ready to execute. Note that in order for such a system to function properly, the
OS must be able to load multiple programs into separate areas of the main memory and provide the required
protection to avoid the chance of one process being modified by another one. Other problems that need to be
addressed when having multiple programs in memory is fragmentation as programs enter or leave the main
memory. Another issue that needs to be handled as well is that large programs may not fit at once in memory
which can be solved by using pagination and virtual memory.
AMD (Advanced Micro Devices) is an American multinational company that creates semiconductors,
processors and other hardware for computers. It was founded in 1969 and has been in a constant battle for
market share with Intel. Intel Corporation is also an American multinational company that produces
semiconductors and other hardware for computing systems. It was founded in 1968, one year before AMD and
has managed to capture approximately 70% of the market.
In an attempt to capture the market it is often under legal disputes as it has been known to employ a lot of
‘underhand’ techniques to maintain the leader in the market. In 1975, AMD and Intel had a short partnership
working on Intel’s 8080
microprocessor for IBM. However, that partnership quickly dissolved with each company starting its own
endeavors. While, Intel’s objective is to provide the most technologically advanced systems, AMD offers the
customers’ value for their money. AMD processors are usually cheaper compared to Intel processors of the
same architecture. The main rivalry between the companies is often boiled down to motherboards and
processors.
The primary difference between AMD and Intel motherboards is that they only accept the same kind of
processor. Hence, an AMD motherboard would only work with an AMD processor, and likewise, an Intel
motherboard will only work with an Intel processor, and not the other way around. The reason for this is the
fact that each processor requires a different socket type. Intel motherboards have LGA 1156 and LGA 1366
sockets, while AMD motherboards have AM2 and AM3 sockets.
However, the fact that an AMD motherboard would only work with an AMD processor, and likewise for Intel,
the sales and market share of Intel and AMD motherboards directly correspond to the sales and market share
38
CE341: Microprocessor Architectures and Assembly Programming 16CE068
of Intel and AMD processors. The number of slots and the amount of RAM that the motherboard can
accommodate is mainly dependent on the make and model of the motherboard. This of course has an effect on
pricing. Hence, a motherboard with more SATA ports and/or with more RAM compatibility will cost more.
Pentium is the brand of processors that belong to Intel, while AMD sells the processors under the AMD name
itself. The Pentium processor is a consumer-level product. It is placed higher than the low-end Atom and
Celeron products but below the faster Core i3, i5, i7 and the Xeon processors. As compared to Intel Core,
Pentium has a lower clock frequency, a partially disabled L3 cache, in addition to disabled hyper-threading
and virtualization. One of the main difference between the processors is the fact that Intel is often more
expensive than its AMD equivalents. This generalization also applies to Pentium. This price difference is often
driven by Intel, as it often holds the top spot when comparing the performance of microprocessors.
Also, Intel processors, such as Pentium have longer pipelines than AMD processors. This allows them to have
a much higher clock speed than what could be normally achieved. However, AMD has found another way to
compete with the increased clock speed, in the means of storing and accessing the CPU memory.
Intel Pentium processors store their memory in an L2 (level 2) cache. This is almost double the size of AMD
Athlon processors’ cache. The L2 cache is a memory bank that stores and transmits data to the L1 (level 1)
cache. The L1 (level 1) cache in turn, stores and transmits data to the processor itself. Hence, the larger the L2
cache, the faster the processing speed.
AMD Athlon processors have roughly half the L2 cache space of a Pentium processor; however its L2 cache
space is integrated directly into the processor itself. This allows AMD Athlon processors to access their cache
data much
quicker than Intel Pentium processors, providing a faster processing speed despite its size. So, even though
technically AMD Athlon processors’ clock rate and cache space are listed as less on paper, it provides
comparable performance to Intel Pentium and all at a relatively lower price.
Both the companies aim to come out with the next best thing and stay a step ahead of each other. Hence, their
products are always closely related with minor differences that each of the company thinks will make their
product better. Due to this, the processors of the two companies are virtually the same.
AMD Intel
39