0% found this document useful (0 votes)
2 views

COAL_2023 - Lecture 16 - Exam Examples

The document outlines tasks and examples related to computer organization and assembly language, focusing on hexadecimal representation, instruction execution, and memory manipulation. It includes exercises on registers, procedures, string processing, and hardware interrupts, as well as specific programming tasks to demonstrate understanding. Key topics include arithmetic operations, loop instructions, and video memory management in different modes.

Uploaded by

starius112
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

COAL_2023 - Lecture 16 - Exam Examples

The document outlines tasks and examples related to computer organization and assembly language, focusing on hexadecimal representation, instruction execution, and memory manipulation. It includes exercises on registers, procedures, string processing, and hardware interrupts, as well as specific programming tasks to demonstrate understanding. Key topics include arithmetic operations, loop instructions, and video memory management in different modes.

Uploaded by

starius112
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Tasks included in the exam could be based on variations of code

examples discussed in lectures


Important:
▪ Hexadecimal representation of integer numeric values in registers
and memory
▪ Execution of simple instructions including arithmetic calculations
▪ Loop instruction, nested loops
▪ String processing
▪ Procedures, instructions CALL and RET, parameter passing
▪ Interrupts, interrupt vectors, hardware and software interrupts
▪ Keyboard basics
▪ Programmable Interval Timer and sound
▪ Video card basics (text mode and graphics mode)
Computer Organization and Assembly Language 1
Task
Integer numeric value N in doubleword format is defined.
N dword 267
Write internal hexadecimal code of each of the bytes starting from the
address N.

N N+1 N+2 N+3


ANSWER (hexadecimal value): 0B 01 00 00

267 = 256 + 11 = 100h + 0Bh = 10Bh

Computer Organization and Assembly Language 2


Task
Array of five integer numeric values (in word format) is defined. Each of the five
values are stored in two bytes. Address of the first element of the array is N.
Write internal hexadecimal code of the memory byte with address N+4.

N word 1, 10, -10, 12, -15

Write content of the memory byte N+4(two hexadecimal digits without any other
symbols).
ANSWER: F6

Explanation:

N N+1 N+2 N+3 N+4 N+5 N+6 N+7 N+8 N+9


01 00 FF
0A FF
00 FE
F6 FF
FF 2A
0C 00
00 F1 FF

Computer Organization and Assembly Language 3


Task
General purpose register EBX contains internal code (hexadecimal):
010203F9

What will be value of the register BX after execution of the following


instructions?

inc ebx 010203FA


mov bh, 0FFh 0102FFFA BX = FFFA = -6
add bx, 7 01020001 BX = -6 + 7 = 1

ANSWER (decimal value): 1

Computer Organization and Assembly Language 4


Task
What internal code of the memory field R will be after execution of the
following instructions?
.data
val byte -1, 2, -3, 4, 5, -6, 7, 8 ; array given
R word 0
.code
start proc
mov esi, 2
mov ax, 0
mov ecx, 2
B: add al, val[esi]
add esi, 2
loop B
mov R, ax
; ::::::::::
start endp
end start

R R+1
ANSWER (hexadecimal value): 02 00

Computer Organization and Assembly Language 5


Task
Fragment of the code to find number of the ampersand symbols (&) in
the zero terminated text given. Write missing instruction(s) in the box to
complete this code.
.data
txt byte '012&456&891&ABC', 0 ; text string

.code
start proc
mov dx, 0
mov edi, 0
check: cmp txt[edi], 0 Write missing
je done instructions here
cmp txt[edi],’&’
jne next
jne next
inc
inc dx
eax
next: inc edi
jmp check
done: ; number of ampersand symbols is in dx

Computer Organization and Assembly Language 6


Task
Procedure Zeros receives one doubleword parameter via stack and returns in the
register EAX number of bits which contain zero in this doubleword.
Zeros proc near
push ebp
mov ebp, esp
push ebx
push ecx
; MISSING INSTRUCTION(S)
xor ebx, ebx …
mov ecx, 32
t: test eax, 1 ESP → …  ESP after RET 4
jnz next
first parameter [EBP+8] → value
inc ebx
next: shr eax, 1 at the entry to Zeros ESP → EIP  ESP after POP EBP
loop t
mov eax, ebx after mov ebp,esp: EBP and ESP → EBP  ESP after POP EBX
pop ecx
pop ebx after PUSH EBX ESP → EBX  ESP after POP ECX
pop ebp
after PUSH ECX ESP → ECX
ret 4
Zeros endp …
Which is a correct instruction to insert in the line of code marked by the comment?
A. mov eax, [ebp+12]
B. mov eax, [ebp+8]
C. mov ecx, [ebp+8]
D. mov ecx, [esp+8]
7
E. None of the above
Task
Procedure Zeros receives one doubleword parameter via stack and returns in the
register EAX number of bits which contain zero in this doubleword.
Zeros proc near stdcall
push ebp
mov ebp, esp
push ebx
push ecx
mov eax, [ebp+8]
xor ebx, ebx
mov ecx, 32
t: test eax, 1
jnz next
inc ebx
next:shr eax, 1
loop t
mov eax, ebx
pop ecx
pop ebx
pop ebp
ret 4
Zeros endp
Write instructions to call this procedure and count zero bits in the doubleword Beta
defined as Beta dword -12
ANSWER:
push Beta
call Zeros 8
Task
A program is given to show message “CapsLock and LCtrl keys are down” if CapsLock and
LeftCtrl keys are both held down at the moment when this code is executed. Some instructions
are missing. Write one or more missing instructions in the code lines marked by the comment.
.model small
.data
msgInit byte "Press any key or Esc to exit!", 13, 10, "$"
msgDown byte "CapsLock and LCtrl keys are down", 13, 10, "$"
.code
.startup
mov ah, 9h
mov dx, offset msgInit
int 21h
xor bx, bx
mov es, bx
tst: ; MISSING INSTRUCTIONS

mov dx, offset msgDown


mov ah, 9
int 21h
notBothDown:
mov ah, 0 ;BIOS interrupt service
int 16h ;wait for key press
cmp ah, 1 ;Esc scan code?
jne tst
.exit
1 ? ? ? ? ? 1
?
end and 0 1 0 0 0 0 0 1
0 1 0 0 0 0 0 1
ANSWER :
mov al, es:0418h
and al, 01000001b
cmp al, 01000001b 9
jne notBothDown
Task

Programmable Interval Timer (PIT) is used to generate sound on computer’s internal


speaker. What value must be loaded to the counter register of the PIT Channel 2 in
order to generate output sound of approximately 100 Hz frequency?
The oscillator provides roughly 1193182 Hz input to each channel of the PIT. Counter
register of PIT channel contains 16 bit non-signed positive value.
ANSWER (decimal value): 11932

Explanation
Each input impulse from the oscillator decrements the counter register by 1. When the
counter has reached 0 the output is generated and the counter is reset again to the
initial value. For example, if the initial counter value is 10 the output impulse will be
generated after each 10 input impulses, i.e. output frequency will be 1193182/10 ≈
119328 Hz (Output = Input/Counter).
To calculate counter value for the output frequency required you may use a formula
Counter = Input frequency / Output frequency.
In this case to generate 100 Hz sound the counter register should contain value
1193182/100 = 11932.

Computer Organization and Assembly Language 10


Task

Video adapter is in the VGA graphics mode 12h with 16 colors and 640x480 pixels
resolution. How many bytes are used to store information in the video memory about
one horizontal line of 640 red color pixels?
ANSWER: 320

Explanation
In the VGA graphics mode each pixel on the screen corresponds to one bit in all display
planes of the video memory. High order bit of the byte A000:0000 corresponds to the
pixel in the upper left corner of the screen. Each display plane memory has the same
starting address A000:0000.
Combination of bits from all display planes determines the colour of the pixel. To encode
16 different colours 4 display planes are used (4 bits may store 16 different unsigned
values from 0 to 15). To store the information about one pixel VGA uses one bit in each
of the 4 display planes.
For 640 pixels of the horizontal line 80 bytes are used in each of the display planes (one
byte for 8 pixels). So 320 bytes are used to store information about 640 pixels long
horizontal line (80 bytes x 4 planes). Colour of the line does not matter.

Computer Organization and Assembly Language 11


Task
Video adapter is in the VGA text mode with 25 rows, 80 symbols per row and 16
colors for symbols. Two letters OK should be displayed in the second row of the
screen starting from the second position. Write one or more missing instructions in
the code lines marked by the comment to assign corresponding value to the register
AX.
.model small
.code
.startup
; MISSING INSTRUCTION(S)
; set address
mov bx, 0B800h
mov es, bx ; segment value for text mode video memory
mov di, ax ; offset
; write symbols and attributes
mov byte ptr es:[di], 'O'
mov byte ptr es:[di+1], 01110100b ; white background, red symbol
mov byte ptr es:[di+2], 'K'
mov byte ptr es:[di+3], 01110100b ; white background, red symbol
.exit
end
ANSWER: mov ax, 162

Explanation: In this VGA text mode each two bytes (one word) in the video memory contains
information about one symbol on the screen. Information about the first symbol in the first
row is in two bytes at address B800:0000. To calculate offset value you may use formula
12

offset = 2*((row-1)*80 + (col-1)). In this case offset = 2*((2-1)*80+(2-1))= 162

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy