GROUP ASSIGNMENT
CT124-3-1-ISC
INTEGRATED COMPUTER SYSTEMS
INTAKE CODE: NP2F2411IT
Hand out date:
Hand in date:
Student’s Name University Id
Dipendra Bhatta NP070499
Chandra Prakash Bhatta NP070498
Tejasbi Gupta NP070514
Nikhil Khadka NP070506
Table of Contents
1. Introduction........................................................................................................................9
2. Overview of the Assignment..................................................................................................9
3. Shape Description: Line.......................................................................................................10
3.1. Code Explanation for Text Mode:.................................................................................10
3.2. Code Explanation for Graphic Mode:...........................................................................11
4. Shape Description: Rectangle..............................................................................................14
4.1. Code Explanation for Text Mode:.................................................................................14
4.2. Code Explanation for Graphic Mode:...........................................................................16
5. Shape Description: Circle....................................................................................................19
5.1. Code Explanation for Text Mode:.................................................................................19
5.2. Code Explanation for Graphic Mode:...........................................................................21
6. Shape Description: Square...............................................................................................28
6.1. Code Explanation for Text Mode:.................................................................................28
6.2. Code Explanation for Graphic Mode:...........................................................................30
7. Shape Description: Triangle.............................................................................................34
7.1. Code Explanation for Text Mode:.................................................................................34
7.2. Code Explanation for Graphic Mode:...........................................................................36
8. Final Code for Shape Description........................................................................................41
8.1. Code Explanation:.........................................................................................................41
8.2 Output for Final Code....................................................................................................58
9. Error Handling in Our Case Study...................................................................................72
9.1. Detecting invalid inputs:...............................................................................................72
9.2. Preventing Crashes........................................................................................................73
9.3. Safely Continuing or Reporting Errors......................................................................73
10. Task 1: Branch Prediction and Caching.............................................................................74
10.1. Branch Prediction........................................................................................................74
10.2. Caching.......................................................................................................................76
Task 2: Comparative Study of Programming Approaches......................................................78
11.1. Performance................................................................................................................78
11.1.1. CPU and low-level optimizations:.......................................................................78
11.1.2. Memory management and scheduling:................................................................79
11.1.3. Ease of Use:..........................................................................................................79
11.1.4. Development complexity:....................................................................................80
11.1.5. OS components (processes, interrupts, memory):................................................80
11.1.6. Security and Stability:..........................................................................................80
11.2. Application in OS Development:............................................................................81
12. Task 3: Future Enhancements and Proposals.....................................................................82
12.1. Future Enhancement of Branch Prediction and Caching Techniques.........................82
12.1.1. Dynamic branch prediction which enhances accuracy and performance by AI-
powered:...........................................................................................................................82
12.1.2. Executing many possible paths of execution concurrently, and more efficient
making of decisions about branches:...............................................................................82
12.1.3. Plastic caching which adapts to the present situation and predicts the
requirements which are likely to occur in the future:......................................................83
12.1.4. A stacked three-dimensional layered memory cache design:..............................83
12.1.5. Unifies the processes of caching and prediction control level:............................83
12.2. Benefits of Combining Low-level and High-level Programming Approach in OS
Design..................................................................................................................................83
12.2.1. Building the components using Assembly and C programming languages in areas
in which a high performance is crucial:...........................................................................83
12.2.2. An easy-to-use programming language which is able to maintain modular code
and make the system safe:................................................................................................84
12.2.3. A blend and flexible strategy of efficient control of resources in different
systems:............................................................................................................................84
12.2.4. Faster breakthroughs and less risk exposure throughout testing and creating:....84
12.2.5. Enhanced management and utilization of resources of various hardware
elements:..........................................................................................................................84
13. Conclusion..........................................................................................................................85
14. References.........................................................................................................................86
15. Work Matrix.......................................................................................................................88
List of Figures
Figure 1: Assembly Code for Line...........................................................................................10
Figure 2: Output for Line.........................................................................................................11
Figure 3: Assembly Code for Line in Graphic Mode (Part 1).................................................12
Figure 4:Assembly Code for Line in Graphic Mode (Part 2)..................................................13
Figure 5:Output for line in Graphic Mode...............................................................................14
Figure 6: Assembly Code for Rectangle..................................................................................14
Figure 7: Output for Rectangle................................................................................................15
Figure 8: Assembly Code for Rectangle in Graphic Mode (Part 1).........................................17
Figure 9: Assembly Code for Rectangle in Graphic Mode (Part 2).........................................18
Figure 10: Assembly Code for Rectangle in Graphic Mode (Part 3).......................................19
Figure 11: Output for Rectangle in Graphic Mode..................................................................19
Figure 12: Assembly Code for Circle......................................................................................20
Figure 13: Output for Circle.....................................................................................................21
Figure 14: Assembly Code for Circle in Graphic Mode (Part 1).............................................22
Figure 15: Assembly Code for Circle in Graphic Mode (Part 2)............................................23
Figure 16: Assembly Code for Circle in Graphic Mode (Part 3)............................................24
Figure 17: Assembly Code for Circle in Graphic Mode (Part 4)............................................25
Figure 18: Assembly Code for Circle in Graphic Mode (Part 5)............................................26
Figure 19: Assembly Code for Circle in Graphic Mode (Part 6)............................................27
Figure 20: Output for Circle in Graphic Mode........................................................................27
Figure 21: Assembly Code for Square (Part 1)........................................................................29
Figure 22: Assembly Code for Square (Part 2)........................................................................30
Figure 23: Output for Square...................................................................................................30
Figure 24: Assembly Code for Square in Graphic Mode (Part 1)...........................................32
Figure 25: Assembly Code for Square in Graphic Mode (Part 2)...........................................33
Figure 26: Assembly Code for Square in Graphic Mode (Part 3)...........................................34
Figure 27: Output for Square in Graphic Mode.......................................................................34
Figure 28: Assembly Code for Triangle...................................................................................35
Figure 29: Output for Triangle.................................................................................................36
Figure 30: Assembly Code for Triangle in Graphic Mode (Part 1)........................................37
Figure 31: Assembly Code for Triangle in Graphic Mode (Part 2)........................................38
Figure 32: Assembly Code for Triangle in Graphic Mode (Part 3)........................................39
Figure 33: Assembly Code for Triangle in Graphic Mode (Part 4)........................................40
Figure 34: Output for Triangle in Graphic Mode.....................................................................40
Figure 35: Code of [Link]-Line, Circle, Square, Rectangle & Triangle (Part-1).....42
Figure 36: Code of [Link]-Line, Circle, Square, Rectangle & Triangle (Part-2).....43
Figure 37: Code of [Link]-Line, Circle, Square, Rectangle & Triangle (Part-3).....44
Figure 38: Code of [Link]-Line, Circle, Square, Rectangle & Triangle (Part-4).....45
Figure 39: Code of [Link]-Line, Circle, Square, Rectangle & Triangle (Part-5).....46
Figure 40: Code of [Link]-Line, Circle, Square, Rectangle & Triangle (Part-6).....47
Figure 41: Code of [Link]-Line, Circle, Square, Rectangle & Triangle (Part-7).....48
Figure 42: Code of [Link]-Line, Circle, Square, Rectangle & Triangle (Part-8).....49
Figure 43: Code of [Link]-Line, Circle, Square, Rectangle & Triangle (Part-9).....50
Figure 44: Code of [Link]-Line, Circle, Square, Rectangle & Triangle (Part-10)...51
Figure 45: Code of [Link]-Line, Circle, Square, Rectangle & Triangle (Part-11)...52
Figure 46: Code of [Link]-Line, Circle, Square, Rectangle & Triangle (Part-12)...53
Figure 47: Code of [Link]-Line, Circle, Square, Rectangle & Triangle (Part-13)...54
Figure 48: Code of [Link]-Line, Circle, Square, Rectangle & Triangle (Part-14)...55
Figure 49: Code of [Link]-Line, Circle, Square, Rectangle & Triangle (Part-16)...56
Figure 50: Code of [Link]-Line, Circle, Square, Rectangle & Triangle (Part-17)...57
Figure 51: DOSBox Setup for Final Code...............................................................................58
Figure 52: Main Menu Execution for Line..............................................................................58
Figure 53: Shape Option for Line............................................................................................59
Figure 54: Color Option for Line.............................................................................................59
Figure 55: Output for Color Options, Green for Line..............................................................60
Figure 56: Output for Color Options, Sky Blue for Line.......................................................60
Figure 57: : Output for Color Options, Purple for Line..........................................................60
Figure 58: Shape Options for Non-colored line.......................................................................61
Figure 59: Output for Non-colored Line..................................................................................61
Figure 60: Main Menu Execution for Circle............................................................................61
Figure 61: Shape Options for Circle........................................................................................61
Figure 62: Color Options for Circle........................................................................................62
Figure 63: Output for Color Options, Green for Circle..........................................................62
Figure 64: Output for Color Options, Sky Blue for Circle.....................................................63
Figure 65: Output for Color Options, Purple for Circle..........................................................63
Figure 66: Shape Options for Non-Colored Circle..................................................................63
Figure 67: Output for Non-Colored Circle...............................................................................64
Figure 68: Main Menu Execution for Square..........................................................................64
Figure 69: Shape Options for Square.......................................................................................64
Figure 70: Color Options for Square........................................................................................65
Figure 71: Output for Color Options, Green for Square.........................................................65
Figure 72: Output for Color Options, Sky Blue for Square....................................................65
Figure 73: Output for Color Options, Purple for Square........................................................66
Figure 74: Shape Options for Non-Colored for Square..........................................................66
Figure 75: Output for Non-Colored Square.............................................................................66
Figure 76: Main Menu Execution for Rectangle......................................................................67
Figure 77: Shape Options for Rectangle..................................................................................67
Figure 78: Color Options for Rectangle...................................................................................68
Figure 79: Output for Color Options, Green for Rectangle.....................................................68
Figure 80: Output for Color Options, Sky Blue for Rectangle...............................................68
Figure 81: Output for Color Options, Purple for Rectangle....................................................69
Figure 82: Output for Non Colored Rectangle.........................................................................69
Figure 83: Main Menu Execution for triangle.........................................................................69
Figure 84: Shape Options for Triangle.....................................................................................70
Figure 85: Color Options for Triangle.....................................................................................70
Figure 86: Output for Color Options, Green for Triangle.......................................................71
Figure 87: Output for Color Options, Sky Blue for Triangle..................................................71
Figure 88: Output for Color Options, Purple for Triangle......................................................71
Figure 89: Output for Non Colored Triangle...........................................................................72
Figure 90: Invalid Input Message Screen.................................................................................73
Figure 91:Branch Prediction Architecture...............................................................................74
Figure 92: Branch Target Instructions.....................................................................................74
Figure 93: Correlated Branch Predictor...................................................................................75
Figure 94: Cache-aside Architecture........................................................................................76
Figure 95: The Browser Cache................................................................................................76
Figure 96:Page View Counting Architecture with Cache and Workers..................................77
Figure 97: Hierarchy of Programming Languages: Machine, Assembly, and High-Level Code
Examples..................................................................................................................................77
List of Table
Table 1: Workload Matrix........................................................................................................88
1. Introduction
The assignment is a mix of practical and research-based programming as well as
analytical skills in developing technical and theoretical competence in systems design. It is
here that the practical element of the course would be able to form an assembly language
program that is able to output the basic shapes like lines, rectangles, circles, squares, and
triangles. By using direct hardware interaction, management and optimization of memory and
using methods such as loop unrolling and instruction pipelining, the project demonstrates the
performance and accuracy which low-level control enables. Explicit error handling is brought
into particular consideration, thus invalid inputs, unforeseen circumstances, and even
hardware problems can be handled without program crashing so that the program could be
run smoothly and without complications.
The programming effort is accompanied by the research part of the work, which studies
and covers important techniques of system performance, namely, the branch prediction and
caching techniques, which are crucial in the current processors, to achieve a low latency and
enhance speed of reaction. The paper also contrasts the merits of low-level assembly and
flexibility and security of high-level languages and shows the roles of both in the
development of operating systems. This assignment can both advance the appreciation of
system-level optimization and underline the need to consider optimization techniques at the
hardware level as well as the high-level design to create an efficient and yet versatile
computing system.
2. Overview of the Assignment
In this group assignment of the Integrated Computer Systems course there are two
significant sections whose grades count 25 percent each and they are Assembly Programming
and Research & Analysis. It is dedicated to the implementation of machine and assembly
language, in an effort to achieve an efficient Shape Generation System in terms of resources,
as well as to build an analysis on the important performance methods of systems, such as
branch prediction and caching. Part 1 (Section A) demands that students develop and execute
an assembly language program (with the help of NASM or other intelligent assembler)
capable of drawing elementary figure shapes like lines, rectangles, circles, squares and
triangles. The program has to access the hardware directly and make the best use of memory,
and performance to achieve optimal performance, e.g. loop unrolling and instruction
pipelining. The code must be neat, well commented and a strong error handling code must be
there to handle wrong inputs or hardware failures. Another evaluation factor is innovation
and creativity in implementation and the presence of a well-documented report.
Section B (the second section) is focused on theoretical knowledge gained by research
and comparisons. Students need to learn how the technique of a branch prediction is used to
maximize the performance of a CPU by stalling the pipeline least and caching decreases
access times to commonly accessed data and hence overall responsiveness of the system. It is
anticipated that evidences found in real world and on the existing operating systems will be
provided during the discussion. A comparison of low level assembly programming with the
high level languages utilized in OS programming also needs to be conducted and they will be
weighed upon based on the basis of performance, ease, security, and practical implementation
such as in kernel designing, memory management and systems calls. The last exercise in this
part requires to make suggestions as to the future things which can be done to improve branch
prediction and caching, as well as the possible advantages of low- and high-level
programming methods to create more efficient and flexible operating systems. The project as
a whole aim not only to provide students the practical experience in coding at the lower level
but also create the profound understanding of the system-level techniques in optimization in
conceptual terms as well.
This assignment combines the practical application of technical programmer skills
and theoretical research and gives the students a task to create an optimized practical system
in assembly language and evaluate system performance strategies. The project blends
implementation and critical analysis so well that it is alone a compelling reason to study
computer systems comprehensibly, and therefore, a crucial component of systems-level
programming or design of an operating system.
3. Shape Description: Line
3.1. Code Explanation for Text Mode:
This is a 16-bit real mode DOS program in assembly, which shows the simple
input/output examples interrupting BIOS. The first program also starts with the org 0x100,
which defines the initial location of the .com file. In data section, it specifies a simple
horizontal line string terminated with newline characters in front and after, and terminated by
a $ sign in the end, which should be recognized by the DOS function to see where the string
ends. In the code section it establishes an interruption 21h, with a service 09h to print the
string in the screen, it then makes interrupt call 21h set to 01h awaiting a single key press by
the user. Finally, it employs interrupt 21h with a function 4Ch to clean exit the demonstrates
simple text output, text input and closure of program in DOS with BIOS interrupts.
Figure 1:
Assembly Code for Line
Figure 2:
Output for Line
3.2. Code Explanation for Graphic Mode:
It begins by org 0x100, which is an indication that it is a .com file, which will be
executed starting at memory location 0x100. It puts the screen into graphics mode, loading ax
= 0x113 and calling int 10h, and this triggers 320x200 4-color CGA graphics mode (Mode
13h) a typical graphics mode allowing one to set each individual pixels. The starting point of
the line that is to be drawn is that a = cx = 0 (starting X), and b = dx = 100 (Y). They also set
the si register to set the length of the line set which is assumed to be initially 200 and bl is set
to 200 determining the color value of the line (in normal Mode 13h however, only values 0-
255 count, usually 0-15 visible).
In loop draw_line, the programe tests whether the value is equal to zero of the length
of a line (si). Otherwise, it detects interrupt 10h which makes ah= 0ch that sets a pixel on
screen. This color is kept in al (bl motor_copied) and, the X and Y coordinates are read
thereof as cx/dx. The navigation bh = 0 is chosen, and this chooses the video page which is
the current page. It looks through the loop and counts X coordinate (cx) as well as reverses
the length counter (si) which essentially draws the left to right pixels on the screen.
Once the line completion comes (si = 0), it enters into its wait mode where it would
wait until a key is entered by using int 16h ah = 0. The it switches back to the text mode
(mode 3) and loads ax = 3 and calls int 10h. Next, termination of the program to DOS is done
by int 21h with ax = 4c00h.
Figure 3:
Assembly Code for Line in Graphic Mode (Part 1)
Figure 4:
Assembly Code for Line in Graphic Mode (Part 2)
Figure 5:
Output for line in Graphic Mode
4. Shape Description: Rectangle
4.1. Code Explanation for Text Mode:
This assembly program will show a basic ASCII rectangular pattern on the screen
under DOS. It starts with org 0x100, showing that it is supposed to be a .com file, which will
run program at memory offset of 0x100. Under the data section, the rectangle pattern will be
presented as multi-line string by exploitation of an asterisk, (*) with an empty character,
which is represented as a top, sides and bottom borders of a rectangle. The carriage return and
line feed characters (13,10) are used to go to the next line at the end of a line, and termination
of the string also requires symbol dollar sign ($) because the DOS interrupt 21h operation
09h needs it to know whether it has reached the end of the string. In the code section, the
program initializes to ah 09h along with dx item. For the dx, it has to identify the rectangle
string and send interrupt 21h to transfer it to appear on the screen. Once it shows the patterns,
it waits, through the use of interrupt 16h and setting ah variable to 0 until a key is pressed.
And lastly, the program code ends in an exit without any junk, the program calls interrupt 21h
with ax = 4c00h, and leaves the control back to the DOS operating system.
Figure 6:
Assembly Code for Rectangle
Figure 7:
Output for Rectangle
4.2. Code Explanation for Graphic Mode:
This machine code will draw a rectangle frame on computer screen in graphics mode
of 320x 200 (Mode 13h) using BIOS interrupt int 10h in DOS. It uses low level graphics calls
to manually draw all of each of the borders of the rectangle (top, bottom, left and right). This
program begins with setting the video mode ox13 which gives a resolution of 320x200 with
256 colors. After that it copies the pixels one by one through BIOS interrupt int 10h function
0Ch. It then employs the loop and the horizontal bit (inc cx), to plot the top and the bottom
straight lines of a rectangle along with plotting the pixels on the drawn width (si = 150). It
then constitutes the vertical sides on the left and falsely credited with it half the designated
height on the right (di = 70). The light blue (bl = 9) is the one whose starting point of the
rectangle is set at (80, 80). After drawing the four borders the program waits on the key press
by call int 16h so that it can put the program to text (mode 3) and window will go to DOS by
calling the int 21h. In this program it is demonstrated how simple shapes can be created by
simply manipulating the pixels of the video memory without going through the BIOS
graphics interrupts.
Figure 8:
Assembly Code for Rectangle in Graphic Mode (Part 1)
Figure 9:
Assembly Code for Rectangle in Graphic Mode (Part 2)
Figure 10:
Assembly Code for Rectangle in Graphic Mode (Part 3)
Figure 11:
Output for Rectangle in Graphic Mode
5. Shape Description: Circle
5.1. Code Explanation for Text Mode:
This DOS assembly program is written to produce a text based circle like pattern on
the screen. It starts with org 0x100 which means it is a .COM file and which is processed
starting at memory address 0x100. In the data section, the figure known as circle_pattern is
created where ASCII symbols are used like asterisk (*) and blank space in order to represent
a circle. The carriage return(13) and line feed(10) character at the end of each line causes the
cursor to rest at the new line in display screen, and the string ends with dollar sign($), which
is necessary according to DOS interrupt functions to indicate the end of the string (09h). In
the text section, the program initializes AH to 09h and in DX input the address of the circle
pattern and inevitably calls to interrupt 21h to have the pattern on the screen. After printing
the program waits a press by a key through interrupt 16h with AH=0 that will halt execution
until one of the keys got pressed. The complete closing off of the program is made through
the call interrupt 21h by using AX = 4C00h. This is an extremely small program, which
produces output of text, and does a little user interaction through DOS interrupts.
Figure 12:
Assembly Code for Circle
Figure 13:
Output for Circle
5.2. Code Explanation for Graphic Mode:
This assembly program has the graphics mode that avails the Midpoint Circle
Algorithm that draws a circle with the BIOS interrupts (320x 200 256 colors, the graphics
mode 13h). It speaks of pixel plotting, symmetry and algorithmic drawing, it is also a low-
level DOS graphics routine. It begins by running a program that switches video mode to 0x13
which has 320 x 200 pixel and 256 colour. It then draws a circle of a centre point value of
(160, 100), its radius is 50 pixels and colour code = 14 i.e yellow (color = 14). It is a circle
built using the algorithmically optimal Midpoint Circle Algorithm that uses the symmetry of
a circle and division by objects made of integer to calculate the perimeter of a circle. The
procedure of plotting the eight symmetrical points of the circle per iteration, Plot8_points is
only applied to perform computing savings. The draw_circle function implements some of
the parameters that is required in the decision and executes all the required points up until
what is required in accordance of fully drawing the circle. All the pixels are to be plotted
through BIOS interrupt int 10h and functional 0Ch. When a drawing is finished a message is
displayed at key press after which the program returns to text mode (mode 3) and exits to
DOS. The program may appropriately be termed as a successful demonstration of algorithmic
drawing of the form using a pixel plotting at the level of BIOS.
Figure 14:
Assembly Code for Circle in Graphic Mode (Part 1)
Figure 15:
Assembly Code for Circle in Graphic Mode (Part 2)
Figure 16:
Assembly Code for Circle in Graphic Mode (Part 3)
Figure 17:
Assembly Code for Circle in Graphic Mode (Part 4)
Figure 18:
Assembly Code for Circle in Graphic Mode (Part 5)
Figure 19:
Assembly Code for Circle in Graphic Mode (Part 6)
Figure 20:
Output for Circle in Graphic Mode
6. Shape Description: Square
6.1. Code Explanation for Text Mode:
This assembly program is employed to display a pattern of squares that is made up of
numerous asterisks (*) on the DOS textual mode. This begins with org 0x100 that is a file
format [Link]. The size of the square that is being stored in the data section, in the form of
an integer, is through the use of variable square_size which can be adjusted (e.g. 6 when the
square is a 6 x 6). This then loads the row count into CX and a subsequent count of columns
is done using a pair of nested loops, used to first count the rows then the columns. It is
essentially identical to the technique above, but on each iteration of the column loop it
displays another instance of a * character (via interrupt 10h and teletype device 2) in order to
be able to increase width of the squares. It gives carriage return and line feed after printing a
line so that it comes to the next line. The print out continues till it covers the whole square. It
must be printed and waits until there is a key press thereafter exiting cleanly by use of DOS
interrupt 21h.
Figure 21:
Assembly Code for Square (Part 1)
Figure 22:
Assembly Code for Square (Part 2)
Figure 23:
Output for Square
6.2. Code Explanation for Graphic Mode:
This is a filled yellow square at the center of the screen, which is written in BIOS
Interrupts under 320x200 256-color graphic mode (Mode 13h) assembly program (this
assembly). It applies the direct pixel plotting, along with the pure math because it aligns the
square. The program starts by executing BIOS interrupt 10h with graphics mode of 0x13 that
enables the resolution of 320x200 as well as 256 colour palette. It calculates the placement of
the top-left corner of the square: it centers the square based on the specifications of the screen
(which means that the size of the square (50 pixels) is subtracted by its screen specifications
and divided by 2). Such values are recorded in the first horizontal (x0) and vertical (y0
position). It will then be entering a nested loop since the outer loop will iterate through each
of the rows of the square (square_size rows) and the inner loop will iterate through each of
the columns of the square, one dot at a time by using interrupt 10h function 0Ch. Each pixel
is calculated in the X and Y coordinates against x0 and y0, thereby the square is at the centre.
Once all the rows and columns are complete the program will wait with int 16h then switches
back to the text mode (mode 3) and exits to DOS properly with int 21h. This diagram
explains the step-by-step procedure to draw a filled figure under the command of single pixel
with the help of BIOS interrupts.
Figure 24:
Assembly Code for Square in Graphic Mode (Part 1)
Figure 25:
Assembly Code for Square in Graphic Mode (Part 2)
Figure 26:
Assembly Code for Square in Graphic Mode (Part 3)
Figure 27:
Output for Square in Graphic Mode
7. Shape Description: Triangle
7.1. Code Explanation for Text Mode:
This DOS assembly code can be used to create a triangular pattern by using ASCII
characters. It begins with an org 0x100, so it is [Link] file. The pattern of the triangle is stored
in the data section in form of a series of paragraphs in the text separated by spaces and
asterisk marks (*), which visually forms a triangle. The carriage return (13) and line feed (10)
appear at the end of line to a new line and the pattern is terminated by a $, which is a
mandatory parameter needed by DOS interrupt 21h function 09h to define end of the string.
At the code section, the program places AH = 09h and DX with the address of the triangle
pattern, and follows it up by call of int 21h, to show it. It just sits in wait of a keyboard press
via int 16h and cleanly exits via int 21h with AX = 4C00h. The program illustrates the
minimal text output and interaction in the DOS through BIOS interrupts.
Figure 28:
Assembly Code for Triangle
Figure 29:
Output for Triangle
7.2. Code Explanation for Graphic Mode:
Initializing the program is done by calling int 10h to switch to graphics mode 13h that
provides resolution of 320 x 200 with 256 colors. The three lines will be used to form the
triangle which will be; left diagonal line, right diagonal line and the base. To set initial
coordinates, the CX, and the DX registers are used, and the number of line length is placed in
the SI, and a color code in the BL. In each line, the procedure draw-line is called, that checks
the form of the current element of the variable line_type, in case of the value equal to 0 draws
a left (goes to the left and down); in case it equals 1 draws a right (goes to the right and
down); otherwise draws horizontal, base line (goes to the right). It does all these by looping
through all pixels checking whether each one exists or not using int 10h function 0Ch and
advances y and x coordinates until the entire length has been drawn. After the drawing of the
triangle we wait until key is pressed back to text mode (mode 03h) and a call to exit to DOS
(int 21h). One can use a single procedure to serve several directions with the help of the use
of line_type variable.
Figure 30:
Assembly Code for Triangle in Graphic Mode (Part 1)
Figure 31:
Assembly Code for Triangle in Graphic Mode (Part 2)
Figure 32:
Assembly Code for Triangle in Graphic Mode (Part 3)
Figure 33:
Assembly Code for Triangle in Graphic Mode (Part 4)
Figure 34:
Output for Triangle in Graphic Mode
8. Final Code for Shape Description
8.1. Code Explanation:
This is a text and graphics shape diagram program written in x86 real-mode assembly
language, targeted to run on DOS. It begins with a main menu where the user can choose one
of several figures: Line, Circle, Square, Rectangle, or Triangle, or close the program. Once
choosing a shape, the user opens a shape-specific menu allowing him/her further to either
draw the shape in color using a graphics mode, open a non-colored ASCII display of the
shape, or gets back to the main menu.
In case the user selects the colored label, it will take the user to a color-choice menu,
with selections such as, Green, Sky Blue, and Purple. Depending on the choice made by the
user, the program will switch to video graphics mode (controlled by BIOS interrupt 10h,
mode 13h 320x200 resolution, 256 colors were available) and then the user-selected shape is
then drawn by various pixel manipulation at the low level. The logic of drawings of each
shape is specific: circles are drawn with the help of the midpoint circle algorithm (with
symmetry rectangles and squares are filled with the help of two nested loops - it is the same
horizontally or diagonally, and triangles are constructed using three lines, which represent
two sides and the base.
The program utilizes BIOS and DOS interrupts to perform several tasks such as
clearing the screen, moving the cursor around, reading the keyboard, and printing strings.
Routines utility are included to switch between graphics and text mode, obtain an input and
plot a pixel. In case a user chooses to see the ASCII image of a shape, then the program will
use hard-coded text patterns placed in the data segment.
After making a diagram, the program requires a key press so as to go back to the
preceding menu or proceed to another selection. When the user quotes that it is over, the
program clears the screen and with a polite exit continues through the DOS interrupt 21h. The
program displays, in general, interactive menu-driven two-dimensional shape drawing with
ASCII and graphical pixel display, both requiring low-level input/output processing as well
as graphics drawing in assembly language.
Figure 35:
Code of [Link]-Line, Circle, Square, Rectangle & Triangle (Part-1)
Figure 36:
Code of [Link]-Line, Circle, Square, Rectangle & Triangle (Part-2)
Figure 37:
Code of [Link]-Line, Circle, Square, Rectangle & Triangle (Part-3)
Figure 38:
Code of [Link]-Line, Circle, Square, Rectangle & Triangle (Part-4)
Figure 39:
Code of [Link]-Line, Circle, Square, Rectangle & Triangle (Part-5)
Figure 40:
Code of [Link]-Line, Circle, Square, Rectangle & Triangle (Part-6)
Figure 41:
Code of [Link]-Line, Circle, Square, Rectangle & Triangle (Part-7)
Figure 42:
Code of [Link]-Line, Circle, Square, Rectangle & Triangle (Part-8)
Figure 43:
Code of [Link]-Line, Circle, Square, Rectangle & Triangle (Part-9)
Figure 44:
Code of [Link]-Line, Circle, Square, Rectangle & Triangle (Part-10)
Figure 45:
Code of [Link]-Line, Circle, Square, Rectangle & Triangle (Part-11)
Figure 46:
Code of [Link]-Line, Circle, Square, Rectangle & Triangle (Part-12)
Figure 47:
Code of [Link]-Line, Circle, Square, Rectangle & Triangle (Part-13)
Figure 48:
Code of [Link]-Line, Circle, Square, Rectangle & Triangle (Part-14)
Figure 49:
Code of [Link]-Line, Circle, Square, Rectangle & Triangle (Part-16)
Figure 50:
Code of [Link]-Line, Circle, Square, Rectangle & Triangle (Part-17)
8.2 Output for Final Code
Figure 51:
DOSBox Setup for Final Code
Note: It shows DOSBox setup where the c:/assembly folder is mounted, and the [Link]
assembly file is compiled into [Link] using NASM for execution.
Figure 52:
Main Menu Execution for Line
Note: If we run [Link], it displays the main menu and offers six options: Line, Circle, Square,
Rectangle, Triangle, and Exit. The user is prompted to enter a choice or exit the programs.
Figure 53:
Shape Option for Line
Note: When we enter 1 from main menu, it shows share options, where the user can choose
to draw the selected shape as Colored, Non-colored or Back to Main Menu.
Figure 54:
Color Option for Line
Note: After running Colored options. It offers 4 color options: Green, Sky Blue, Purple, and
Back.
Figure 55:
Output for Color Options, Green for Line
Note: When we enter 1 (Green) from Color Options. It shows green line.
Figure 56:
Output for Color Options, Sky Blue for Line
Note: When we enter 2 (Sky Blue) from Color Options. It shows sky blue line.
Figure 57:
Output for Color Options, Purple for Line
Note: When we enter 3 (Purple) from Color Options. It shows purple line and if we enter 4
it’s back to share options.
Figure 58:
Shape Options for Non-colored line
Note: After running colored option, we move to non-colored options for non-colored line.
Figure 59:
Output for Non-Colored Line
Note: When the user enters 2 (Non-colored) it shows the non-colored line.
Figure 60:
Main Menu Execution for Circle
Note: From main menu, when the user enters 2 (Circle). It shows the shape drawing options.
Figure 61:
Shape Options for Circle
Note: A shape options shows the menu where the user enters their choice like colored
options.
Figure 62:
Color Options for Circle
Note: After run the shape options for colored, it shows 4 types of options.
Figure 63:
Output for Color Options, Green for Circle
Note: When we enter 1 (Green) from color options. It shows green color circle.
Figure 64:
Output for Color Options, Sky Blue for Circle
Note: When user run color options and enter 2 (Sky Blue). It shows sky blue color circle.
Figure 65:
Output for Color Options, Purple for Circle
Note: When user run color options and enter 3 (Purple). It shows purple color circle and if
user enter 4 (back) then it’s back to shape options.
Figure 66:
Shape Options for Non-Colored Circle
Note: When user run colored options then enter the non-colored options for circle.
Figure 67:
Output for Non-Colored Circle
Note: After run the non-colored options and when enter 3. It’s back to main menu.
Figure 68:
Main Menu Execution for Square
Note: After selecting the shape options like line, circle, then we enter for square option.
Figure 69:
Shape Options for Square
Note: After choosing from main menu. It shows shape options like colored and soon.
Figure 70:
Color Options for Square
Note: After the shape options where the user has options to choose different colors.
Figure 71:
Output for Color Options, Green for Square
Note: When user run color options and enter 1 (Green). It shows green color square.
Figure 72:
Output for Color Options, Sky Blue for Square
Note: When user run color options and enter 2 (Sky Blue). It shows sky blue color square.
Figure 73:
Output for Color Options, Purple for Square
Note: When user run color options and enter 3 (Purple). It shows purple color square and if
user enter 4 (back) then it’s back to shape options.
Figure 74:
Shape Options for Non-Colored for Square
Note: When we enter 2 it shows the non-colored rectangle.
Figure 75:
Output for Non-Colored Square
Note: When user choose non-colored options and user back to enter 3. It’s back to main
menu.
Figure 76:
Main Menu Execution for Rectangle
Note: After selecting the shape options from main menu like line, circle, square then we enter
for rectangle option.
Figure 77:
Shape Options for Rectangle
Note: A shape options shows the menu where the user enters their choice like colored
options.
Figure 78:
Color Options for Rectangle
Note: The user chooses from color options to draw shape as their choice.
Figure 79:
Output for Color Options, Green for Rectangle
Note: When user run color options and enter 1 (Green). It shows green color rectangle.
Figure 80:
Output for Color Options, Sky Blue for Rectangle
Note: When user run color options and enter 2 (Sky Blue). It shows sky blue color rectangle.
Figure 81:
Output for Color Options, Purple for Rectangle
Note: When user run color options and enter 3 (Purple). It shows purple color square and if
user enter 4 (back) then it’s back to shape options.
Figure 82:
Output for Non Colored Rectangle
Note: When the user chooses non colored option, it shows the non-colored rectangle.
Figure 83:
Main Menu Execution for triangle
Note: After selecting the shape options like line, circle, square, rectangle, triangle, and exit
option. The user has choice to select a specific shape or exit.
Figure 84:
Shape Options for Triangle
Note: The shape options where the user enters their choice to selected colored options.
Figure 85:
Color Options for Triangle
Note: After the shape options, user enter the color options where user select their color.
Figure 86:
Output for Color Options, Green for Triangle
Note: When we enter 1 (Green) from color options. It shows green color triangle.
Figure 87:
Output for Color Options, Sky Blue for Triangle
Note: When we enter 1 (Sky Blue) from color options. It shows sky blue color triangle.
Figure 88:
Output for Color Options, Purple for Triangle
Note: When user run color options and enter 3 (Purple). It shows purple color triangle and if
user enter 4 (back) then it’s back to shape options.
Figure 89:
Output for Non Colored Triangle
Note: After select the shape options, the user chooses the non-colored options then it shows
non-colored triangle.
[Link] Handling in Our Case Study
9.1. Detecting invalid inputs:
In our assignment overviews the process of error handling with identifications
of wrong user inputs. In case a user enters a value not included in the menu, the system does
recognize the fact, that it is an invalid input right away and gives a clear message: “Invalid
Entry! Please enter a valid option.” This is aimed at ensuring that the program runs normally
even through a wrong value, either in the form of wrong menu selection or parameters will
not have adverse effect with the programming running. The system can avoid anomalous
operation by checking the inputs it processes thus confines the user in the visualized list of
choices on shapes, colors, and exit commands.
Figure 90:
Invalid Input Message Screen
Note: In case the user enters a non-valid number, the program shows “Invalid entry! Please
enter a valid option”, which reminds the user to key in a valid menu option.
9.2. Preventing Crashes
The other significant matter of error handling is not letting the program crash
because of incorrect actions or hardware problems. The program securely handles video
memory; switching between int 10h text mode and graphics mode. It also automatically
returns the screen back to text mode before it is terminated and this prevents the system
ending up in an unstable state of video. Likewise, once a drawing loop is finished the
application Freezes and waits until a key is pressed rather than crashing into out of
bounds memory. These precautions smoothen the way of the program execution without
system instability and crash.
9.3. Safely Continuing or Reporting Errors
This case study also describes how the program can go on without any disaster
once a blunder or an unauthorized input is detected. Rather than uncivilly terminating, it
directs the user back to the corresponding menu so that they may re-input a valid response or
cease use in the main menu. In such a manner, the system either skips the drawing of invalid
form, sets an exit safe valve, or issues an error message. The method will facilitate a seamless
user experience because the application will be interactive, fault tolerant, and easy to use
even in the event of an error.
10. Task 1: Branch Prediction and Caching
10.1. Branch Prediction
Branch prediction is a key tool in today’s computer architecture used to decrease wait
times for instructions and speed up the computer. If an "if-else" statement is reached, the
CPU has to choose between the two possibilities provided. Branch prediction lets the
processor make an anticipated guess and go ahead with the next action. Doing this ahead of
time reduces waits in the pipeline, making it easier to send and complete instructions (Baer,
2012). If branch prediction did not exist, the CPU would have to stop running until the branch
is decided which results in inefficiency and drops performance.
Figure 91:
Branch Prediction Architecture
Source: (Koc, 2006)
Branch predictions help the processor work more efficiently. As soon as the processor
foresees the correct outcome of a branch, it can continue to run other instructions without
stops which leads to swifter and more responsive action. Above all, getting a prediction
wrong is expensive, as the CPU throws out the wrong command and begins executing again
from where it is meant to (Yokota & Oostsu, 2008). Since deeply pipelined architectures
process instructions at the same time, the misprediction penalty can be very high. A longer
pipeline makes inaccurate guesses about branch control have a bigger effect, therefore
advanced branch prediction methods are required for high performance.
Figure 92:
Branch Target Instructions
Source: (Sainrat, 1996)
Managing how tasks are executed and what to execute next is one-way operating
systems improve branch prediction. They collaborate with hardware in order to make sure
instructions are processed smoothly (Dumas, 2016). Newer processors make use of 2-bit
predictors and Branch Target Buffers (BTB) that examine old execution paths to guess future
behavior. By using these techniques, the chance of wrong predictions goes down and the
system works more effectively. It is also common for some processors to use a form of
predictor that uses history to estimate future branches better.
Figure 93:
Correlated Branch Predictor
Source: (Learning Lounge, 2018)
For example, Intel processors have dynamic branch prediction that uses past information
and evolves models to lessen delays in execution (Comprehensive Dictionary of Electrical
Engineering, 2019). Hybrid predictors are used in these CPUs, allowing them to Accuracy by
using a mix of several prediction techniques. Optimization helps greatly in resource-limited
areas, making sure the system continues to function efficiently. Branch prediction improves
how well programs are executed and helps systems respond more quickly which is why it is
an essential part of today’s processors (Dougherty, 2020).
10.2. Caching
Caching helps a system run better by saving data that is used often in memory areas
that work faster. Rather than waiting for data from slower sources, caching makes frequently
used information faster and more efficient to get. Current operating systems use this
technique to make sure that popular data can be accessed quickly and is not held up because
of slow management (Nagaraj, 2004). Using caching, programs can avoid loading the same
data from storage several times which improves performance and reduces workload.
Figure 94:
Cache-aside Architecture
Source: (scylladb, n.d.)
There are various forms of caching that are chosen for different ways to speed up a
system. Using CPU caching, often-used information is stored in special fast memory which
improves how quickly the system works (Kleppmann, 2017). Because commonly accessed
files are kept in memory with disk caching, disk operations are decreased and it becomes
easier to retrieve data. Having web caching stores older web pages which makes it faster and
less necessary to download them more than once (Grigorik, 2013). All of these techniques for
temporary data storage join forces to improve data accessibility whenever necessary.
Figure 95:
The Browser Cache
Source: (ichip, 2023)
The job of handling cache allocation and removal policies is given to operating
systems, who do it to ensure memory is managed efficiently. By using Least Recently Used
(LRU) and Write-Through caching, memory use is reduced and unnecessary consumption is
avoided. Because of proper cache management, OS ensure that data is both reliable and
accessed as fast as possible (Turcheva, 2015). Also, with modern caching, data is stored in a
sequence of caching layers, arranged by the how much each data is accessed. By using this
setup, the most commonly used information is placed where it can be reached the fastest
which benefits performance.
Figure 96:
Page View Counting Architecture with Cache and Workers
Source: (Nguyen, 2021)
For example, Linux uses LRU caching to ensure memory is used wisely and the
system responds faster. By using this method, the most important data is kept easy to access
so it is readily available. Adaptive caching algorithms on Windows help change how much
space is allocated in cached memory depending on demands (Decker, 2025). With caching
systems, operating systems save resources, reduce how hard the system works and ensure
better system response in places where resources are limited. Caching helps data access be
quick and makes the entire system run more smoothly (Team, 2025).
Task 2: Comparative Study of Programming Approaches
Both low-level assembly (e.g. x86 NASM) and high level languages such as C/C++
serve purposes in the development of an operating system but are highly differentiated in
their degree of control, complexity, and safety. Through assembly, the programmer has full
control over hardware with fine grain, and this enables potentially very minimal and very
specific code possible. C and C++ have rich abstractions, structured syntax and portability.
Modern operating system kernels (Windows, Linux, macOS) are a blend of the two: Linux
has a kernel that is primarily in C with some parts written in assembly, and Windows is
nearly pure C/C++ with select portions hand-written in assembly. This report is a comparison
of NASM based assembly language vs C/C++ in its development of OS.
Figure 97:
Hierarchy of Programming Languages: Machine, Assembly, and High-Level Code Examples
Source: (Miya, 2023)
11.1. Performance
11.1.1. CPU and low-level optimizations:
Assembly language can be optimized instruction-by-instruction hence e.g., branchless
code sequences and cache alignment. As an example, a compiler-generated function (std:
max) introduced conditional/*moved (cmov) instructions in order to remove unpredictable
jumps. An expert assembly programmer may manually lay out instructions or data to be
cached or in pipelines to achieve maximum efficient performance ( Performance profiling,
n.d.). But the currently most powerful C/C++ compilers also do aggressive optimizations.
Practically, a good C compiler will generate better machine code than even the best assembly
coders. In fact, C/C++ can also have intrinsic, or inline assembly, to get the hardware-level
control when necessary (andrewthompson555, [Link], n.d.). In general, assembly can
steal away such microscopic performance that you can achieve similar performance using
high-level code without having to compromise on maintainability, which becomes critical
when working with third parties (AMD (Advanced Micro Devices, n.d.).
11.1.2. Memory management and scheduling:
In both methods the OS writer has to do his own memory allocation (buddy
allocators, page tables, etc.). An assembly is not a more efficient way to code a program, it
simply does what the programmer tells it to do. In contrast C permits more straightforward
implementations both of allocators and data structures (both of which must be manually
managed). Task scheduling is algorithmic work: they are written in C (Linux) or C++
(windows kernel) and built on scheduler logic as opposed to their language. Context-switch
paths can be optimized by assembly but big scheduling decisions occur in C/C++
(Advantages and Disadvantages of Assembler, 2023). In short, assembly provides much more
immediate control (e.g. hand-implemented spin loops or register concurrency) but C/C++ will
tend to match it in performance with well-tuned compiled code and is easier to modify
quickly.
11.1.3. Ease of Use:
High-level languages dramatically reduce development complexity. Writing OS
routines (process creation, memory allocators, interrupt handlers) in C or C++ is far easier
than in raw assembly. C/C++ offer rich type systems, standard libraries, and clearer syntax
for constructs like loops and data structures. Assembly requires manually saving/restoring
registers, managing the stack, and encoding every operation in detail, which is error-prone. In
contrast, C provides abstractions (structs, pointers, functions) that make kernel logic concise.
As Kaashoek et al. point out, high-level languages “reduce programmer effort” through
abstraction and automated memory management (in user-level languages). Even though
kernels typically avoid features like garbage collection, C’s built-in pointer arithmetic and
library routines simplify tasks like buffer manipulation or linked lists. For interrupt handling,
an assembly stub might save registers and jump to a C handler, but designing that in pure
assembly would be very complex. In short, C/C++ greatly ease writing and maintaining code
for scheduling, allocation, and syscall logic, whereas NASM requires verbose, low-level
coding.
11.1.4. Development complexity:
Complexity of assembly: Assembly is verbose and error susceptible. Each instruction,
label and register have to be written by hand, and high-level logic (loops, function calls)
needs boiler plate code. Writing in assembly, one summary states, is much harder work . . .
and the complexity grows nearly exponentially with the complexity of the data structures
(andrewthompson555, Why do people say C is better than Assembly?, n.d.) . In comparison,
C/C++ offer functions, structures and libraries of code which reduces the code size
drastically. As an example, working out a linked list or file system is much easier in C using
structs and pointers, than writing out the pointer arithmetic by hand in assembly. This
minimizes bugs: assembler programs are more susceptible to errors and bugs, compared to
high-level language programs (Advantages and Disadvantages of Assembler, 2023).
11.1.5. OS components (processes, interrupts, memory):
The lowest-level stubs are usually just assembly: the bootloader, CPU initialization,
interrupt entry/exit or critical context-switch code. The simplest OSDev tutorial has NASM
to initialize protected mode and execute to a C-based kernel which does absolutely nothing
(an infinite loop), demonstrating that assembly language is largely configuration. The
majority of the OS features (process management loops, memory allocators, device drivers)
can be implemented in C/C++ in a more readable way. C code is easier to read and maintain
by most OS developers: “the bulk of existing example code is written in C; most
programmers can read C more easily than assembly”. In practice, hobby kernels are a mixture
of both: e.g., core scheduling in C, but a pair of assembly calls to save registers. In general
C/C++ are used to radically increase productivity in the field of OS programming, whereas
assembly is used only to refine or interface with the hardware.
11.1.6. Security and Stability:
Both do not necessarily block hardware attacks, though, and both are of concern when
it comes to safety. Spectre attacks and Meltdown exploit the speculative execution of the
CPU, and work against code of any language. Such micro architectural bugs target both
assembly and compiled C/C++ and so are mitigated through CPU/microcode patches as well
as through compiler/kernel patches rather than being influenced by selecting one of the
languages. It is even more serious in regard to memory safety: NASM and C do not provide
built-in checks and garbage collection. According to Kaashoek et al., a large proportion of
kernel bugs are C code (e.g. in 2017, there are 50+ Linux CVEs with buffer overflows or use-
after-free in C). In assembly there is explicit manipulation of stack frames and memory by the
programmer so when a programmer overruns a buffer or leaks a stack memory, they do it
entirely by hand. C permits a small subset of compiler defense (stack canaries, static
analyzers), and safer idioms (e.g., limiting the size of memcpy), but remains a source of
discipline. In a C/C++ kernel, some classes of bugs could be removed using high-level
languages (such as Go or Rust) due to type safety and managed memory, which is not the
case. Practically, assembly writing provides no magical protection: the accidental dropped
pointer acts the same. Actually, C and C++ kernels frequently implement further safety
measures (e.g. -fstack-protector) which pure assembly code would have to implement by
hand. All in all, low level programming requires a careful approach to prevent memory leaks
and overflow vulnerabilities but the high level constructs minimize yet do not eliminate those
risks.
11.2. Application in OS Development:
Assembly and C/C++ have complementary roles in practice. Most kernels are mostly
coded in C (or C++) with important low-level components in assembly language. As an
example, the source tree of Linux contains large volumes of C code to implement core
functionality, whereas startup code, context-switch code, and some other functions are in
assembly (so-called architecture-dependent startup and context-switch code) (Getting started
with the linux kernel module, 2014). Most of the Linux kernel is written in C, although
assembly language is used to bootstrap (set up CPU mode and caches) and to handle interrupt
entry/exit (save registers, issue iret), etc. Windows also utilizes C/C++ kernel (and also some
drivers), moving to assembly code only in rare cases (e.g., in some interrupt paths or low
level routines) (Object-oriented design patterns in the kernel, part 1, 2011). Driver code and
system-call logic are usually implemented in C: drivers are implemented using C interfaces
and infrastructure code and may have small amounts of inline assembly for speed (optimized
copy loops). When final performance, or the ability to control the device, is required,
assembly language may be useful: Hyde observes that certain programmers require, to
achieve the required efficiency or device control abilities, which are only attainable through
assembly language (usually specific context-switching or cryptographic loops. But since
assembly is not portable, kernels sparingly use it. Kernels written in high-level C allow it to
maintain the code across architectures (the building system chooses the proper arch/ assembly
to use on any particular CPU). Briefly, NASM may be used to bootstrap the first time around,
and possibly some expert optimizing, but C/C++ is the kernel design language, system call
programming language, and driver language.
Sources: Peer-reviewed and official sources such as OS kernel documentation and academic
papers were used (see citations above) for data on performance, control, and vulnerabilities in
assembly vs. C/C++.
12. Task 3: Future Enhancements and Proposals
12.1. Future Enhancement of Branch Prediction and Caching Techniques
Future efforts to achieve further benefits in terms of system performance in resources-
limited settings should concern co-designing hardware and software, prediction with the help
of AI, and caching with a consideration of context.
12.1.1. Dynamic branch prediction which enhances accuracy and performance by AI-
powered:
The dynamic branch prediction techniques, as found on modern CPUs, the
Tournament Predictors and Perceptron Predictors, are also constrained by fixed algorithms.
In the future, it is possible to incorporate machine learning models, more precisely
reinforcement learning (RL), to more effectively learn the branching nature of the certain
workload on a real-time basis. See an example of a neural branch predictor that might
dynamically change its prediction strategy depending upon program phase or CPU usage
patterns. This would radically decrease misprediction penalties and increase pipelines
effective use, especially in natively multi-execution paths such as mobile or embedded
systems (enez).
12.1.2. Executing many possible paths of execution concurrently, and more efficient
making of decisions about branches:
Speculative multithreading, which is closely related to speculative execution, permits
a system to run multiple potential code paths concurrently before knowing which is
potentially required, and thus speculative multithreading may save time provided that the
right path has been guessed. Although this is at present expensive and cumbersome, CPUs of
the future might implement inexpensive, speculative threads that can execute difficult-to-
predict branches in parallel, but will only commit to executing, and only after speculation,
one of them. This, together with check pointing techniques when applied can guarantee
stability in the system without affecting its performance. These would be useful in operating
systems that require low latency and determinism particularly in real-time operating systems
(RTOS) (Francisco J Cazorla, 2004).
12.1.3. Plastic caching which adapts to the present situation and predicts the requirements
which are likely to occur in the future:
Semantic caching could be used to advantage future caching systems where the
caching would take place as before on the basis of the frequency of use, but also on the basis
of contextual relevance. As an example, when a specific process uses specific libraries or
drivers many times over, the OS can pre-cache corresponding instructions and the data.
Compiler hint or behavior analysis at the runtime may allow the cache controller to prefetch
the pertinent blocks prior to them being requested (A neural network memory prefetcher
using semantic locality).
12.1.4. A stacked three-dimensional layered memory cache design:
Future CPUs are speculative with advancements such as 3D chip stacking (such as
Intel Foveros and AMD 3D V-Cache), which will place large L3/L4 caches closer in
proximity to processing cores, where the memory access latency will drop significantly;
operating systems may thus have to be cache-aware by assigning a cache-intensive task to a
core with optimal cache resources, resulting in an improvement in performance of CPU-
intensive tasks such as AI workloads and database processing, even in small systems.
12.1.5. Unifies the processes of caching and prediction control level:
In future, it is possible that the OS kernels can comprise an integrated layer having the
functionality of dynamically synchronizing the branch prediction plans as well as caching
policies. UCPL is able to optimize each process or each thread in terms of prediction depth
and cache eviction strategies via workload profiling and adaptive heuristic topics. Such a
prediction-caching synergy has the potential to achieve optimal throughput and less stalls in
power and silicon-constrained systems with limited power envelopes.
12.2. Benefits of Combining Low-level and High-level Programming Approach in OS
Design
A combination of low-level (assembly/C) and high-level (C++, Rust, Go)
programming language is beneficial to the design of future operating systems in performance
and flexibility:
12.2.1. Building the components using Assembly and C programming languages in areas
in which a high performance is crucial:
Assembly is more appropriate with bootloaders and interrupt handlers and device
drivers in which cycle-level performance is critical and direct access to hardware is required.
As an illustration, inline assembly is still used in architecture-specific code in the Linux
kernel in tasks such as context switching or atomic memory operations (MaiZure).
12.2.2. An easy-to-use programming language which is able to maintain modular code and
make the system safe:
Memory safety, strong typing and concurrency primitives provided by high-level
languages such as Rust can go a long way towards alleviating vulnerabilities such as buffer
overwrites or race conditions. The Redox OS written in Rust illustrates how high-level
programming languages can comfortably be applied in kernel development without making
its performance compromise.
12.2.3. A blend and flexible strategy of efficient control of resources in different systems:
The use of the two techniques can enable the system developers to optimize the parts
that require a high level of performance without neglecting the rest in terms of readability,
maintainability, and security. As an example, a memory manager may decide to use C to give
it tight control, but the rest of the scheduler logic may use C++ to give it stronger abstraction
and extension properties.
12.2.4. Faster breakthroughs and less risk exposure throughout testing and creating:
High-level abstractions are more comfortable when dealing with speculative
techniques (such as branch prediction or prefetching), prototype, simulate and iterate. In the
meanwhile, after validation, the performance-sensitive components may be re-implemented
in the optimized low-level code. This division accelerates the R&D processes in the
development of OS (Reinhard Budde, 2012).
12.2.5. Enhanced management and utilization of resources of various hardware elements:
Operating systems of the future may make use of a hybrid programming model to
optimize performance within a heterogeneous computing environment (including CPUs,
GPUs, and NPUs) by automatically assigning tasks to specialize processing units. High-level
logic will be able to coordinate the complex activities and low-level drivers effectively
communicate with definite processing units maximizing utilization and responsiveness
(Hwu).
13. Conclusion
The conclusion of this assignment brings out the compromise between practice and
theory in the design of the system. The shape generation system based on the use of the
assembly language can evidence how low-level languages can directly work with the
hardware, increase performance and stability by means of error handling. It also demonstrates
that even elementary tasks such as drawing shapes need to be very conscious of memory,
processor instructions, and user touches to avoid mishaps or crashes. The branch prediction
and caching research and the comparison of assembly language programming and high-level
language programming keep the research valuable insight as to how efficiency is met in the
processors and operating systems, and how each language should be used maximizing each
based on its effectiveness. High-level languages are simpler to use and read and can be
maintained in the long-term; Assembly is precise and optimized.
Collectively, these elements attest to the importance of going hand in hand with the
abilities of technical skills along with analytical analysis. Not only did the project increase
hardware level programming skills, it also helped in gaining a more in-depth look at
performance strategies and design decisions in modern operating systems. It encourages
further experimentation with hybrid strategies in which low-level programming might be
applied to key performance tasks and more liberating high-level programming used to
guarantee flexibility and safety. On the whole, the study demonstrates that theoretical
knowledge should not be dissociated with practice since it is necessary to acquire the skills
and knowledge that can be applied to the engineering system development and innovation.
14. References
(n.d.). Retrieved from scylladb: [Link]
Performance profiling. (n.d.). Retrieved from GPUOpen: [Link]
performance-guide/cpu-performance-guide-part1/#:~:text=First%2C%20let
%E2%80%99s%20take%20a%20look,effectively%20avoid%20branch%20prediction
%20failure
(2018, May 07). Retrieved from Learning Lounge: [Link]
Lounge/2018/05/07/[Link]
(2023, August 09). Retrieved from ichip: [Link]
ochistit-prosto-o-slozhnom-256172
A neural network memory prefetcher using semantic locality. (n.d.). Retrieved from
[Link]
Advantages and Disadvantages of Assembler. (2023). Retrieved from
[Link]
Advantages and Disadvantages of Assembler. (2023). Retrieved from
[Link]
assembler/
AMD (Advanced Micro Devices, I. (n.d.). Retrieved from [Link]
andrewthompson555. (n.d.). Retrieved from [Link]: : [Link]
andrewthompson555. (n.d.). Why do people say C is better than Assembly? Retrieved from
[Link]: [Link]
Baer, J.-L. (2012). Microprocessor Architecutre: From Simple Pipelines to Chip
Multiprocessors. Cambridge University Press.
Comprehensive Dictionary of Electrical Engineering. (2019). Taylor & Francis .
Decker, E. (2025). Cache Cloud. MoldStud.
Dougherty, E. R. (2020). Digital Image Processing Methods. Taylor & Francis.
Dumas, J. D. (2016). Computer Architecture. Taylor & Francis.
enez, D. A. (n.d.). Dynamic Branch Prediction with Perceptrons.
Francisco J Cazorla, P. M. (2004). Predictable performance in SMT processors.
[Link]
Getting started with the linux kernel module. (2014). Retrieved from apriorit:
[Link]
%20Linux%20kernel%20is%20written,%E2%80%98%20%3A%3A
%20%E2%80%99
Grigorik, I. (2013). High-Performance Browser Networking. O'Reilly Media.
Hwu, W.-m. W. (n.d.). Heterogeneous System Architecture. eBook .
Kleppmann, M. (2017). Designing Data-Intensive Applications. O'Reilly Media.
Koc, C. (2006, January). Retrieved from ResearchGate:
[Link]
Architecture_fig2_220334553
MaiZure. (n.d.). The evolution of x86 context switching in Linux. Retrieved from
[Link]
Miya, A. ( 2023, January 23). Retrieved from usemynotes: [Link]
language-and-machine-language/
Nagaraj, S. V. (2004). Web Caching and Its Applications. Springer.
Nguyen, T. (2021, January 28). Retrieved from Medium:
[Link]
8cd1cc83afdf
Object-oriented design patterns in the kernel, part 1. (2011). Retrieved from
[Link]
%20the,techniques%20receive%20little%20support%20or
Reinhard Budde, K. K. (2012). Prototyping: An Approach to Evolutionary System
Development.
Sainrat, P. (1996, April). Retrieved from ResearchGate:
[Link]
cycle-t-1_fig3_2619604
Team, V. C. (2025). Essential Books for Developers to Master Caching Concepts. MoldStud.
Turcheva, V. d. (2015). Packt Publishng.
Yokota, T., & Oostsu, K. (2008). Architecture of Computing Systems - ARCS 2008. Springer.
15. Work Matrix
Table 1:
Workload Matrix
S. N Team Member’s Tasks
1. Dipendra Bhatta [NP070499] Shape of Square of both text mode
and graphic mode
Shape of Rectangle of both text
mode and graphic mode
Final Coding of both text mode
and graphic mode
Code Testing and Debug
Description of Branch Prediction
and Caching
2. Tejasbi Gupta [NP070514] Introduction
Shape of Line of both text mode
and graphic mode
Final Coding of both text mode
and graphic mode
Code Testing and Debug
Conclusion
Documentation
Formatting & Proof reading
References & Citations
3. Nikhil Khadka [NP070506] Shape of Triangle of both text
mode and graphic mode
Final Coding of both text mode
and graphic mode
Error Handling
Code Testing and Debug
Description of Comparative Study
of Programming Approaches
4. Chandra Prakash Bhatta [NP070498] Overview of the Assignment
Shape of Circle of both text mode
and graphic mode
Final Coding of both text mode
and graphic mode
Code Testing and Debug
Description of Future
Enhancement and proposals