Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 71

Abertay University

Computing and Engineering Systems

E-COURSEWORK SUBMISSION SHEET

Name: David Gordon Student ID: 1004103

Programme Title: BSc Digital Forensics Stage: 1

Module Number: CE0714A Module Name: Computer Architecture and Operating Systems

Assessment Due Date: 10/01/2011

Module Tutor: Dr I Ferguson

Declaration
I have read and understood the University of Abertay Dundee policy on academic deceit and certify

that the following is all my own work.

I also give permission to the University to check the authenticity of my work using electronic

software and the Internet.

Signed: David Gordon Date: 10/01/2011


Computer Architecture and Operating Systems

David Gordon
1004103

2
First Year Portfolio University of Abertay

University of Abertay

B.Sc. Digital Forensics


2010 - 2011

David Gordon (1004103)


CE0714A
Abstract
The following portfolio has been produced to meet the requirements of the University of Abertay
Dundee’s course CE0714A Computer Architecture and Operating Systems, for the academic years of
2010 – 2011. The portfolio is based upon laboratory work and assignments that were set during the
year.

Acknowledgements
All trademarks and names are owned and copyrighted by their respective owners.

3 University of Abertay

The contents of this document are for educational purposes only.

David Gordon (1004103)


CE0714A
Table of Contents

Abstract.................................................................................................................................................3
Acknowledgements...............................................................................................................................3
Table of Contents..................................................................................................................................4
Table of Figures.....................................................................................................................................6
Tables....................................................................................................................................................6
Hardware Familiarisation......................................................................................................................7
The Motherboard..............................................................................................................................7
The Central Processing Unit.............................................................................................................11
Random Access Memory.................................................................................................................13
Hard Disk Drive(s)............................................................................................................................14
Power Supply Unit...........................................................................................................................16
CD and DVD drive(s)........................................................................................................................16
Network card...................................................................................................................................17
4 University of Abertay
System Profiling...................................................................................................................................19
Memory Profiling.............................................................................................................................19
BIOS Profiling...................................................................................................................................19
Operating System Profiling..............................................................................................................20
Currently, possible results include:..................................................................................................20
Disk Drive Profiling..........................................................................................................................21
Data Representation............................................................................................................................23
Binary..............................................................................................................................................23
Hexadecimal....................................................................................................................................24
Question 1:......................................................................................................................................25
Question 2:......................................................................................................................................25
Question 3:......................................................................................................................................25
Question 4:......................................................................................................................................25
Question 5:......................................................................................................................................26
Question 6.......................................................................................................................................26
Question 7.......................................................................................................................................26
Question 8.......................................................................................................................................28

David Gordon (1004103)


CE0714A
Binary Arithmetic.................................................................................................................................28
Question 1) XOR Output..................................................................................................................29
Question 2 & 3a) NAND Output.......................................................................................................29
Question 3b) NOT OR GATE.............................................................................................................29
Question 3c) XOR AND OUTPUT......................................................................................................30
Question 4a) A AND NOT B GATE....................................................................................................30
Question 4b) A OR (B AND C) GATE.................................................................................................31
Question 4c) (A AND B) NOR (A AND C) GATE.................................................................................31
Question 5) Logic Expression...........................................................................................................32
Question 6) truth Table for Circuit in Question 5.............................................................................32
Manipulating Bits and Bytes in C#.......................................................................................................33
Output:........................................................................................................................................39
Building Adders, Counters and Registers.............................................................................................40
Half Adder........................................................................................................................................40
Bits and PCs.........................................................................................................................................42
Low-Level Programming......................................................................................................................43
A Comparison of Low and High Level Languages.................................................................................44
5 University of Abertay
Error Detection....................................................................................................................................45
References...........................................................................................................................................46

David Gordon (1004103)


CE0714A
Table of Figures
FIGURE 1: EXAMPLE OF A MOTHERBOARD......................................................................................................................8
FIGURE 2: MOTHERBOARD SERIAL NUMBER....................................................................................................................9
FIGURE 3: QUAD CORE INTEL CPU.............................................................................................................................12
FIGURE 4: TRANSCEND DDR3 MEMORY......................................................................................................................14
FIGURE 5: WESTERN DIGITAL 2TB SATA HARD DRIVE...................................................................................................15
FIGURE 6: COMPAQ DVD-ROM................................................................................................................................17
FIGURE 7: GENERIC NETWORK INTERFACE CARD............................................................................................................18
FIGURE 8: TYPICAL BIOS SCREEN...............................................................................................................................20
FIGURE 9: OR GATE BEING FED BY TWO NOT INPUTS.....................................................................................................30
FIGURE 10: A CIRCUIT WITH A XOR AND AND OUT PUTS..............................................................................................31
FIGURE 11: A AND NOT B GATE..............................................................................................................................31
FIGURE 12: A OR (B AND C) GATE...........................................................................................................................32
FIGURE 13: (A AND B) NOR (A AND C) GATE...........................................................................................................32
FIGURE 14: HALF ADDER CIRCUIT DIAGRAM.................................................................................................................41
FIGURE 15: HALF ADDER’S TEST RIG...........................................................................................................................41
FIGURE 16: FULL ADDER CIRCUIT................................................................................................................................42
FIGURE 17: FULL ADDER’S TEST RIG...........................................................................................................................42
FIGURE 18: FULL ADDER TRUTH TABLE........................................................................................................................42
FIGURE 19: 8 BIT ADDER BASED ON 8 X FULL ADDERS....................................................................................................43
FIGURE 20: 8 BIT ADDER IN OPERATION.......................................................................................................................43
FIGURE 21: D-TYPE FLIP-FLOP...................................................................................................................................44
FIGURE 22: -VE EDGE TRIGGERED D-TYPE FLIP-FLOP.....................................................................................................44
6 University of Abertay
FIGURE 23: 4BIT PARALLEL REGISTER..........................................................................................................................45
FIGURE 24: 4 BIT SHIFT REGISTER..............................................................................................................................45
FIGURE 25: 4 BIT UP-COUNTER.................................................................................................................................46
FIGURE 26: 2-TO-4 LINE DECODER.............................................................................................................................46
FIGURE 27: 2-TO-4 LINE DECODER TEST RIG................................................................................................................47
FIGURE 28: 4-16 LINE DECODER................................................................................................................................47
FIGURE 29: 4-16 LINE DECODER TEST RIG...................................................................................................................48
FIGURE 30: 7 SEGMENT LED DISPLAY EXAMPLE............................................................................................................48
FIGURE 31: 0 LED DISPLAY.......................................................................................................................................49
FIGURE 32: 1 LED DISPLAY.......................................................................................................................................49
FIGURE 33: 2 LED DISPLAY.......................................................................................................................................49
FIGURE 34: 3 LED DISPLAY.......................................................................................................................................49
FIGURE 35: 4 LED DISPLAY.......................................................................................................................................50
FIGURE 36: 5 LED DISPLAY.......................................................................................................................................50
FIGURE 37: 6 LED DISPLAY.......................................................................................................................................50
FIGURE 38: 7 LED DISPLAY.......................................................................................................................................50
FIGURE 39: 8 LED DISPLAY.......................................................................................................................................51
FIGURE 40: 9 LED DISPLAY.......................................................................................................................................51
FIGURE 41: A LED DISPLAY.......................................................................................................................................51
FIGURE 42: B LED DISPLAY.......................................................................................................................................51
FIGURE 43: C LED DISPLAY.......................................................................................................................................52
FIGURE 44: D LED DISPLAY.......................................................................................................................................52
FIGURE 45: E LED DISPLAY.......................................................................................................................................52
FIGURE 46: F LED DISPLAY.......................................................................................................................................52

David Gordon (1004103)


CE0714A
FIGURE 47: 7 SEGMENT LED CONTROLLER...................................................................................................................53
FIGURE 48: BCD CONTROLLER...................................................................................................................................54
FIGURE 49: 7 SEGMENT DISPLAY CONTROLLER..............................................................................................................54
FIGURE 50: 8:1 MULTIPLEXOR...................................................................................................................................55
FIGURE 51: 4:1 MULTIPLEXOR...................................................................................................................................56

Tables
TABLE 1: EXAMPLE BINARY SCALE (INCOMPLETE)............................................................................................................23
TABLE 2: THE HEXADECIMAL SCALE.............................................................................................................................24
TABLE 3: EXAMPLE BINARY USAGE CONVERSION SCALE..................................................................................................24
TABLE 4: TWOS-COMPLIMENT VALUE RANGE FOR 16BIT BINARY.....................................................................................25
TABLE 5: BINARY TO DECIMAL CONVERSION TABLE (32 BIT – FIRST 16 BITS)......................................................................26
TABLE 6: BINARY TO DECIMAL CONVERSION TABLE (32 BIT – LAST 16 BITS)......................................................................26
TABLE 7: WORKING OUT FOR QUESTION 5-C................................................................................................................26
TABLE 8: HEXADECIMAL TO BINARY AND DECIMAL CONVERSION......................................................................................28
TABLE 9: BOOLEAN ALGEBRA DESCRIPTION...................................................................................................................28
TABLE 10: XOR TRUTH TABLE...................................................................................................................................29
TABLE 11: NAND TRUTH TABLE................................................................................................................................29
TABLE 12: CIRCUIT TRUTH TABLE...............................................................................................................................29
TABLE 13: : CIRCUIT TRUTH TABLE..............................................................................................................................30
TABLE 14: AND A NOT B GATE TRUTH TABLE............................................................................................................30
TABLE 15: : A OR (B AND C)...................................................................................................................................31
TABLE 16:: (A AND B) NOR (A AND C) TRUTH TABLE.................................................................................................32
7 University of Abertay
TABLE 17: HALF ADDER TRUTH TABLE.........................................................................................................................40

David Gordon (1004103)


CE0714A
Hardware Familiarisation
Digital Forensic specialists are required to be familiar with the internals of computer systems, their
identification and profiling. Without such basic knowledge it would be hard to comprehend how a
digital forensic professional could operate.

Within this laboratory I was required to open a suitable computer system case, identify and
catalogue the main components and conduct some profiling of the components. This was a very
straightforward laboratory as I worked for many years, building and repairing computer systems in a
commercial environment.

The actual hardware components to be identified are:

 Motherboard
 CPU
 RAM
 hard disk
 PSU
 CD/DVD drive
 Network card
8 University of Abertay

The Motherboard
The motherboard has become an increasingly complex central component of any computer system.
In the 1980s motherboards were less complicated with most of the now on-board functions being
controlled by add-on Industry Standard Architecture (ISA) cards. Motherboards come in numerous
form factors (designs), from highly compact and integrated boards for netbooks, to massively
expandable boards more suitable for servers. Boards are also designed for particular central
processing systems (CPU) with the main
two consumer manufacturers being Intel
and AMD.

The board I examined belonged to an


Intel based personal computer. Nearly
all motherboards have clearly
identifiable labels indicating the make,
model and serial number of the board.

Figure 1: Example of a motherboard


David Gordon (1004103)
CE0714A
The labelling could be as simple as a sticky label or the identifiers could be laser etched into the
board itself.

Modern boards have a number of expansion slots; which are predominantly PCI based, correctly
known as (Peripheral Component Interconnect). PCI-E and AGP slots are also commonly available on
consumer motherboards. PCI-E are an enhanced form of the PCI standard, the “E” stands for
Express; and reflects that this PCI slot is generally faster than standard PCI slots which is why the PCI-
E was commonly used for a time to allow faster graphics cards to be added to the system. Now AGP
(Accelerated Graphics Port) slots are used to allow very fast graphics cards to be connected.

It would be wrong to imagine that all motherboards


provide such detailed information. In general the board
only contains a serial number and model number.
However, going to the manufacturer’s web site can reveal
quite detailed information about the board, its capacities
and features, and indeed its year and maybe actual date of
production.
Figure 2: Motherboard serial number

Entering the Model Name, shown in Figure 2, into Google’s


9 University of Abertay
search engine revealed that this particular board was manufactured in Taiwan by Jetway; and the
Jetway site provided in-depth information on the features of the board as shown below:

 VIA VX800 Chipset


 Support VIA C7 1.5GHz(90nm,FSB 400MHz,1.5GHz) processor
 Integrated Chrome9 HC3 DX9 IGP
 Integrated LVDS support 24-bit TFT LCD
 Support 1 x 32-bit PCI slot
 Support 2 x Serial ATA 2 Devices
 Windows Vista Ready
 Onboard Gigabit LAN
 Support DC FAN
 COM2 Support RS422/485 
 VIA VT1708B HD Audio Codec with 6-Channel
 170 x 170mm Mini-ITX Form Factor
 Support Daughter board Expansion
 Support Watch dog Technology

CPU

 Support VIA C7 1.5GHz(90nm,FSB 400MHz,1.5GHz) processor


 Front Side Bus 400MHz

David Gordon (1004103)


CE0714A
Chipset

 VIA VX800 Chipsets


 VIA Chrome9 HC3 IGP, 128Bit 3D engines( Share System Memory:64/128/256MB)

Memory

 1 * 240-pin DIMM Sockets for un-buffered DDR2 667MHz SDRAM up to 2GB

Expansion Slots

 1 * 32-bit PCI slots

Power Management

 ACPI S3/S4 Compliant ,supports VIA PowerSaver™ feature

Storage

 2 * Serial ATA2 3Gb/s connectors with RAID 0,1 functions


 1 * Ultra DMA 133/100/66 IDE connector

Audio

10  VIA VT1708B HD Audio Codec  with 6-Channel University of Abertay

Ethernet LAN

 1 * RTL8111C 10 / 100 / 1000 PCI LAN

USB

 Embedded 6 * USB 2.0/1.1

LVDS

 Onboard 24-bit dual channel LVDS connector

Rear Panel I / O

 2 * USB 2.0/1.1 ports


 1 * PS/2 connector for Keyboard and Mouse
 1 * RJ-45 ports
 3 * Audio I/O ports ( Line-in, mic and line-out )
 1 * VGA port
 1 * DB-9 RS232 COM port

Internal I / O

David Gordon (1004103)


CE0714A
 2 * USB 2.0/1.1 headers for 4 USB 2.0 ports
 1 * CPU Smart Fan Connector, 2 * Sys/Chassis Fan Connectors
 3 * 9-Pin COM Port headers(COM2 Support RS422/RS485)
 1 * IR header
 1 * HDMI_SPDIF header
 1 * LVDS header

BIOS

 Award 4MB SPI Flash ROM

Form Factor

 Mini-ITX Embedded Motherboard(170mmx170mm)

Temperature

 Operating within 0~60 centigrade


 Storage within -20-85 centigrade

There is clearly a wealth of information that can be gained about a motherboard simply by knowing
its serial number or model number. However, being able to access the manufacturer’s web site gives
us access to manuals, drivers, BIOS updates, and of course direct access to their technical support

11 department if it is required for a digital forensic investigation. University of Abertay

David Gordon (1004103)


CE0714A
The Central Processing Unit
The CPU is often referred to as the “brain”[ CITATION And10 \l 2057 ] of the computer. Initially there
was a CPU and a separate FPU (Floating Point Unit) which calculated floating point arithmetic.;
however, modern CPUs have not only incorporated the FPU but often have multiple CPUs (known as
cores) built in. Thus, it is common to have dual and quad core CPUs; and Tilera has announced the
release of a new 100 core CPU[ CITATION Tho09 \l 2057 ].

The CPU comprises tens of millions of transistors; effectively, little switches which can be either in an
on or off state. This polar state is precisely the reason that the internal processing of end user
actions are in binary; as binary mathematics lends itself ideally to the polemic states of the
transistors. Occasionally, the CPU is inaccurately referred to as the base unit, the case, within which
most computer components reside.

CPU serial numbers are normally either etched onto the core
itself or displayed on an attached sticky label. It should be
noted that knowledge of the serial number is not as important
with CPUs as it is for motherboards. Simply the
manufacturer’s name and the model of the CPU displayed on
12 University of Abertay
the top of the core is all that is required to gain all the
information about the core that one could desire.

Again, going to the vendor’s web site will provide more Figure 3: Quad Core Intel CPU
information on the CPU than any digital forensic professional
will ever need. Modern CPUs run hot, that is they generate a great deal of heat and do not function
properly, or for long, if they are not cooled. As a result CPUs are now found under either a large
cooling fan, or under a water cooling heat-sink. These cooling systems need to be removed before
one can access the CPU.

Intel® Core™2 Quad Processor Q9650 (12M Cache, 3.00 GHz, 1333 MHz FSB)

Essentials
Status Launched
Launch Date Q3'08
Processor Number Q9650
# of Cores 4
# of Threads 4
Clock Speed 3 GHz
L2 Cache 12 MB
Bus/Core Ratio 9
FSB Speed 1333 MHz

David Gordon (1004103)


CE0714A
FSB Parity No
Instruction Set 64-bit
Embedded Options Available No
Supplemental SKU No
Lithography 45 nm
Max TDP 95 W
VID Voltage Range 0.8500V-1.3625V
Tray 1ku Budgetary Price $316.00
Package Specifications
TCASE 71.4°C
Package Size 37.5mm x 37.5mm
Processing Die Size 214 mm2
# of Processing Die Transistors 820 million
Sockets Supported LGA775
Halogen Free Options Available Yes

Advanced Technologies
Intel® Turbo Boost Technology No
Intel® Hyper-Threading Technology No
Intel® Virtualization Technology (VT-x) Yes
Intel® Virtualization Technology for Directed I/O (VT-d) Yes
Intel® Trusted Execution Technology Yes
AES New Instructions No
Intel® 64 Yes
Idle States Yes
13 Enhanced Intel SpeedStep® Technology Yes University of Abertay
Intel® Demand Based Switching No
Thermal Monitoring Technologies Yes
Execute Disable Bit Yes

David Gordon (1004103)


CE0714A
Random Access Memory
The computer has numerous types of memory, the standard volatile memory; that is memory which
does not retain its contents after the machine has been powered off, is called the computers RAM.
Most computers have around 4GB of RAM, although much more and sometimes less can be present.
With less memory available to the Operating System and underlying applications the greater the
degree of “swapping” that is required; which in turn, severely
degrades the operational function of the overall system and user
experience.

RAM comes in numerous packages reflecting their optimisation,


speed of communication and processing. It is not particularly
necessary to be aware of the serial number of a memory module,
although it is normally displayed on a sticker on the reverse side of the module. The maker and
model is all that is required to ensure that the module has been set up properly so that no damage
will come to the system they are being attached to; and so no Figure 4: Transcend DDR3 Memory
damage comes to the RAM.

Product P/N: TS512MLK72V3N


14 University of Abertay

Features:
Stable and Durable, Highly Compatible
100% tested
Lifetime Warranty
Specification:
Memory Type: DDR3 Memory
Pin and Module Type: 240Pin Long-DIMM
Frequency: DDR3-1333
Function: ECC Unbuffer Memory
Capacity: 4GB
DRAM: 256Mx8
Voltage: 1.5 V
CL: 9

David Gordon (1004103)


CE0714A
Hard Disk Drive(s)

Figure 5: Western Digital 2TB SATA Hard Drive

For modern computers to be useful, they need to have a non-volatile memory; which allows
information to be saved prior to the shutdown of the computer to a medium which it can be
recovered from after the computer has been restarted. The most typical form of such non-volatile
memory is called a Hard Drive, or Hard Disk.

15 University
Hard disks can be external as well as internal, that is they can be readily attached of Abertay
and detached from
the main system; usually through a USB 2 connection. From the point of a digital forensic
professional it is important to keep this in mind, as a great deal of evidence could be missed if a
proper search for external storage devices is not made.

Traditionally Hard Disk labels contain an abundance of information which allows digital forensic
professionals and system technicians to repair and manipulate the drive at a low level; it also
permits [professionals to calculate disk space – to see if there are hidden volumes on the drive that
the operating system and perhaps discovery software cannot detect.

Performance Specifications
Transfer Rates
Buffer To Host (Serial ATA) 3 Gb/s (Max)

Physical Specifications
Formatted Capacity 2,000,398 MB
Capacity 2 TB
Interface SATA 3 Gb/s
User Sectors Per Drive 3,907,029,168
David Gordon (1004103)
CE0714A
Physical Dimensions
English
Height 1.028 Inches
Length 5.787 Inches
Width 4.00 Inches
Weight 1.61 Pounds

Metric
Height 26.1 mm
Length 147 mm
Width 101.6 mm
Weight 0.73 kg

Environmental Specifications
Shock
Operating Shock (Read) 65G, 2 ms
Non-operating Shock 300G, 2 ms
16 University of Abertay
Acoustics
Idle Mode 25 dBA (average)
Seek Mode 0 29 dBA (average)
Seek Mode 3 26 dBA (average)

Vibration
Operating
Linear 20-300 Hz, .75G (0 to peak)
Random 10-300 Hz, 0.008 g² / Hz

Non-operating
Low Frequency 5-20 Hz, 0.195 inches (double amplitude)
High Frequency 20-500 Hz, 4.0G (0 to peak)

Electrical Specifications
Current Requirements
Power Dissipation
Read/Write 6.00 Watts
Idle 3.70 Watts
Standby 0.80 Watts
Sleep 0.80 Watts

David Gordon (1004103)


CE0714A
17 University of Abertay

David Gordon (1004103)


CE0714A
Power Supply Unit
The PSU is the engine that powers the components
and thus allows the computer to function. Every
component that is added to the system increases
the drain on the PSU; excessive drain can cause
intermittent problems and even a total system
failure. It is because of this, and the ability of users
to expand the original systems they purchase, that
PSUs come with different power levels (wattages)
and are simple pull-out-push-in units.

On the side, or top, of the typical PSU the warning label is displayed announcing the dangers of
working with high voltage apparatus. This is where the manufacturers also traditionally place
information about who made the unit, and its serial and model numbers. Using the model number
and the manufacturer’s name it is possible to get the full data sheet of the PSU from the
manufacturer’s website.

18 University of Abertay
CD and DVD drive(s)
CD drives are not as common
as they once were; however,
DVD drives are very common
particularly the writeable and
re-writeable, and slowly the
popularity of Blue-ray drives
are taking off. The latter are
called Blue-ray after the
colour of laser that is
employed. The colour blue
has a shorter wavelength to
red which is used in more
traditional CD and DVD drives.
Thus a blue laser can pack
more data into the same area Figure 6: Compaq DVD-ROM
as a tradition drive. As these devices operate lasers, they are particular dangerous to take apart and

David Gordon (1004103)


CE0714A
serious eye damage can result. As a result manufacturers place a highly visible label on the device to
ensure that technicians take adequate precautions before taking the device apart. Using the model
number a technician will easily find appropriate drivers for the device if necessary.

Network card

Figure 7: Generic Network Interface Card

It is common for modern computers to have a built in network card, although NICs can also be
purchased separately and inserted into one of the available PCI slots on the motherboard. NICs as
the name suggests allows the computer to connect to networks; and with modern broadband
19 University of Abertay
Internet services it also permits the computer to be connected to a router and through that – the
Internet.

There is not customary location on network cards for discovering the serial number. It may be a label
on the back, front or external facia of the card, it may be inscribed into the board, or there may be
no serial number or part number visually present.

Model USR267900 also available in Canada 1

Specifications and Standards

 Full-duplex IEEE 802.3 10BASE-T


 Full-duplex IEEE 802.3u 100BASE-TX
 Low power 3.3 V device
 Meets PCI Local Bus Specification, Rev.2.1/2.2
 ACPI
 DMI
 Wired for Management (WfM) 2.0 support
 802.3x

Power Consumption
1
[CITATION 10110 \l 2057 ]

David Gordon (1004103)


CE0714A
 +5 V (maximum)

Minimum System Requirements

 Any of the following operating systems: Windows 98SE/NT 4.0/2000/Me/XP, SCO


UNIX, NetWare, and Linux
 Available PCI-bus slot (PCI 2.2 compliant)
 500K available hard disk space for driver installation
 2x or better CD-ROM drive (for Installation CD-ROM)
 RJ-45 Ethernet cable (not included)

Regulatory Compliance

 FCC approved (Part 15 Class B)


 IC approved (ICES-003)
 UL/CUL Listed

Environmental Specifications

 Temperature 32 °to 122 °F/0 °to 50 °C (Standard operating)


 Humidity 10%to 90% (Non-condensing)

Package Contents

20  USRobotics 10/100 Mbps Network Card University of Abertay


 Wake on LAN (WoL) cable
 Quick Installation Guide
 Installation CD-ROM

Package Dimensions/Weight

 Length 9.87 in.(25.08 cm)


 Width 6.37 in.(16.19 cm)
 Height 2.12 in.(5.4 cm)
 Weight 0.75 lb (0.34 kg)

Product Dimensions/Weight

 Length 4.72 in.(12 cm)


 Width 2.56 in.(6.5 cm)
 Height 0.71 in.(1.8 cm)
 Weight 0.12 lb (0.06 kg)

David Gordon (1004103)


CE0714A
System Profiling
The information we gain from the various components’ model and serial numbers can be very
valuable to analysts. However, the real business of profiling a system is normally done through
software whilst the machine is actually running. For this section of the laboratory work I was
instructed to discover the following information:

o How much physical memory does the PC have?


o What is date of the BIOS?
o What version of the operating system is running?
o What make and model of disk drives are installed?
o What is the size of the disk drive?

The target machine is a Microsoft Windows 7 based computer running as a virtual machine on
Oracle’s VirtualBox. The process and software used would remain the same on any machine running
a version of Windows from Windows XP, onwards.

Memory Profiling
System Information revealed that the machine had:

21  2GB Total Memory University of Abertay


 833MB Free Memory
 4GB Total Virtual Memory
 2.5GB Free Virtual Memory
 2GB Page File Space

Task Manager and Resource Monitor could provide further information about memory availability
and usage. For instance, Task manager stated that Firefox was using the most memory at
approximately 258,000K, closely followed by Microsoft Word. The DOS command MEM.EXE may also
be available depending upon which version of Microsoft Windows is being tested.

BIOS Profiling
System Information revealed that the (virtual)
machine’s BIOS reported its date as 01/12/2006.
Although a great deal of information can be gathered
concerning the BIOS during the POST (Power On Self-
Test), when the computer is started – it is easier to
interrupt the POST and physically enter the BIOS
configuration screens. This can be done with a hot key
combination during the POST (see Appendix A).
Figure 8: Typical BIOS Screen

David Gordon (1004103)


CE0714A
The BIOS, Basic Input / Output System, contains a wealth of knowledge about the hardware of the
system being profiled.

Operating System Profiling


System Information provides a lot of information about the operating system and software installed
upon the operating system. The DOS VER command also provides basic information on the OS.
Within the system I profiled VER returned the OS version information as:

 Microsoft Windows [6.1.7600]

System Information translated the version information into a more human understandable name:

Microsoft Windows 7 Professional

 Version 6.1.7600, Build 7600

Currently, possible results include2:


Operating System Version Number Other Information

Windows 1.0 1.04

Windows 2.0 2.11


22 University of Abertay
Windows 3.0 3

Windows NT 3.1 3.10.528

Windows for Workgroups 3.11 3.11

Windows NT Workstation 3.5 3.5.807

Windows NT Workstation 3.51 3.51.1057

Windows 95 4.0.950

Windows NT Workstation 4.0 4.0.1381

Windows 98 4.1.1998

Windows 98 Second Edition 4.1.2222

Windows Me 4.90.3000

Windows 2000 Professional 5.0.2195

Windows XP 5.1.2600 Current SP3

Windows XP Professional x64 Edition 5.2.3790

2
Beta releases have alternative version numbers and are not included in the list above.

David Gordon (1004103)


CE0714A
Windows Vista 6.0.6000 Current Version changed to 6.0.6002 SP2

Windows 7 6.1.7600 RTM

[ CITATION Nir09 \l 2057 ]

Disk Drive Profiling

There are many tools and third party utilities available for profiling computer components including
hard drives. The Microsoft Windows Operating system makes extensive use of the System
Information tool, and current versions of Windows also have an extensive disk management service
and resource monitor; both of which can be used to gain information about the hard drives and
partitions on a system.

System Information tells us that the hard disk I profiled is 247.15 GB (265,375,707,136 bytes), with
199.92 GB (214,666,682,368 bytes) free space. The full System Information summary was displayed
as follows and Appendix B, has a complete listing of the System Information profile for the computer
examined.

 OS Name Microsoft Windows 7 Professional


 Version 6.1.7600 Build 7600
 Other OS Description Not Available
23  OS Manufacturer Microsoft Corporation University of Abertay
 System Name ATHENS
 System Manufacturer innotek GmbH
 System Model VirtualBox
 System Type x64-based PC
 Processor Intel(R) Core(TM)2 Quad CPU Q9550 @ 2.83GHz, 3171 Mhz, 2 Core(s), 2
Logical Processor(s)
 BIOS Version/Date innotek GmbH VirtualBox, 01/12/2006
 SMBIOS Version 2.5
 Windows Directory C:\Windows
 System Directory C:\Windows\system32
 Boot Device \Device\HarddiskVolume1
 Locale United Kingdom
 Hardware Abstraction Layer Version = "6.1.7600.16385"
 User Name Athens\T3kk
 Time Zone GMT Standard Time
 Installed Physical Memory (RAM) Not Available
 Total Physical Memory 2.00 GB
 Available Physical Memory 1.24 GB
 Total Virtual Memory 4.00 GB
 Available Virtual Memory 3.00 GB
 Page File Space 2.00 GB

David Gordon (1004103)


CE0714A
 Page File C:\pagefile.sys

24 University of Abertay

David Gordon (1004103)


CE0714A
Data Representation
A computer system’s Central Processing Unit (CPU) is built from a series of transistors which in effect
are simple off on switches. This means that for a CPU to process user input, perform calculations,
and produce results it must do so, using these polemic switches. Human language is not designed in
such a manner and as such the text that is typed into a computer is not what a CPU processes.
However, we do have a mathematic base numbering system which is polemic; it is known as binary.

Binary allows CPUs to process a user’s input; but it requires a conversion from one form to another.
The characters we type into a keyboard only appear to us as intelligible text; to the computer the
characters are actually represented as binary. The Unicode standard lists all the numbers associated
with almost every character that can be typed in any language, as well as special notations for music,
and mathematics. Unicode 6 literally has tens of thousands of numerical character representations
for hundreds of different scripts.

The Latin letter “J” for example is common enough to English readers; however, to computers it is
0x004A[ CITATION Con10 \l 2057 ]. This is known as a hexadecimal value or the base 16 numerical
system. Humans often use hexadecimal as an alternative to binary because binary representations of
25 University
numbers can be very space consuming, as well as very difficult to understand. This of Abertay
laboratory work is
designed to illustrate the conversion process between Binary, Hexadecimal and Decimal (Base 10)
values; decimal being the most common base numerical system employed by technologically
enabled people.

Binary
Binary numbers consist of either a 0 (zero) or 1 (one), which represent a value which corresponds to
its position on an imaginary scale. The scale which is represented below starts with the values 1, 2, 4,
8, 16 … and is continued by multiplying the previous number by 2. The scale has no logical limit, but
for space reasons are never completed and when related to computers is often converted to
Hexadecimal.

512 256 128 64 32 16 8 4 2 1


Table 1: Example binary scale (incomplete)

The value of 512 (Decimal) would be for example, displayed in binary notation as 1000000000. This
form is rather difficult to read and just as in decimal the “,” is used to separate each 3 rd number a
space is used to separate each 4th number. Thus, 512 would customarily be represented by: 0010
0000 0000. Note the prefixed two zeros which are used for padding.

David Gordon (1004103)


CE0714A
The decimal number 29 would therefore be represented as 0001 1101. That is to generate the
number 29 decimal we require 1x16 + 1x8 + 1x4 + 0x2 + 1x1 which equals 29 decimal. The binary
scale increases in value when reading from right to left and each binary value is called a bit.

Hexadecimal
Hexadecimal is often used to represent binary values within computer science (ibid.). It has already
been shown that binary can be a cumbersome notation to use, but it is needed when we consider
that computer CPUs work purely with binary. To make binary values more human readable, and
writeable, it is often converted to and from hexadecimal. Hexadecimal, or hex as it is commonly
referred to, is denoted either by preceding the hex value with “0x” or by adding the “h” suffix. The
scale range of hex is from 0 (zero) to 9 (nine) and from ”A” through “F”.

Hex 0 1 2 3 4 5 6 7 8 9 A B C D E F

Dec 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
DIGI 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
T
Table 2: The Hexadecimal scale

The alphabetic characters A – F can be displayed as either upper or lower case letters, although it is
traditional not to mix cases.
26 University of Abertay

The following questions are to be answered:

1) Convert the following from decimal to 8-bit binary


a) 19 b) 96 c) 250
2) Convert the following from binary to decimal
a) 0111 b) 101101000011
3) What is the maximum integer that can be represented in 16 bit binary? Give your
answer in
a) Binary b) hex c) decimal
4) What range of numbers can be represented by 16 bit two's complement?
5) Convert the following binary numbers into hexadecimal
a) 101011101011 b) 11100110 c) 11001010111111101011101010111110
6) Perform the following binary additions:
a) 00101 + 10110 b) 100111 + 100101 + 000001
7) Perform the following operations using 8 bit two's complement arithmetic.
a) 100 + 27 b) 84 + 52 c) 115 – 64 d) -85 - 44
8) Convert the following hexadecimal numbers to binary and decimal
a) FF b) B0 c) 1212 d) FACE

Table 3: Example Binary Usage Conversion Scale

16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 Bits
32768 16384 8192 4096 2048 1024 512 256 128 64 32 16 8 4 2 1 DEC

David Gordon (1004103)


CE0714A
0 0 0 1 0 0 1 1 19
0 1 1 0 0 0 0 0 96
1 1 1 1 1 0 1 0 250
0 1 1 1 7
1 0 1 1 0 1 0 0 0 0 1 1 2883
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 65535

Question 1:
a) 0001 0011 = 19
b) 0110 0000 = 96
c) 1111 1010 = 250

Question 2:
a) 0111 = 7
b) 101101000011 = 2,883

Question 3:
a) 1111 1111 1111 1111
b) 0xFFFF
0xF is equal to 1111 (Binary) ∴
1111 1111 1111 1111

F F F F ∴
27 1111 1111 1111 1111 ≡ 0xFFFF University of Abertay
c) 65,535 - 65,536 in real terms because we count the zero value, so 65,535 + 1 = 65,536

Question 4:

Table 4: Twos-Compliment Value Range for 16bit Binary

Binary Value Decimal Value


0000 0000 0000 0000 -32,768

1000 0000 0000 0000 +0

1111 1111 1111 1111 +32,767

The first digit of the binary value represents the singed bit – that is in twos-compliment it tells us
whether it is a positive or negative number – this Signed bit is not used as part of the total value of
the binary value; in twos-compliment the value 1111 does not represent the decimal value of 10 but
is actually representative of +111 (Binary) or the decimal value 7. However, in negative numbers the
full set of binary values is used, this means 0000b is equal to -8 decimal.

David Gordon (1004103)


CE0714A
16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 Bits
3276 16384 819 409 2048 1024 512 256 128 64 32 16 8 4 2 1 DEC
8 2 6
1 0 1 1 1 0 1 0 1 0 1 1 1 1 1 0
Table 5: Binary to Decimal Conversion table (32 bit – first 16 bits)

32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 B
it
s
2147483648 1073741824 536870912 268435456 134217728 67108864 33554432 16777216 8388608 4194304 2097152 1048576 524288 262144 131072 65536

2147 1073 5368 2684 1342 671 335 167 838 419 209 104 52 26 13 65
4836 7418 7091 3545 1772 088 544 772 860 430 715 857 42 21 10 53
48 24 2 6 8 64 32 16 8 4 2 6 88 44 72 6
1 1 0 0 1 0 1 0 1 1 1 1 1 1 1 0
Table 6: Binary to Decimal Conversion Table (32 Bit – last 16 bits) 3

Question 5:
a) 2795
b) 230

c) 1100 1010 1111 1110 1011 1010 1011 1110 =


0xCAFE 0xBABE

Binary 1100 1010 1111 1110 1011 1010 1011 1110


Decima 12 10 15 14 11 10 11 14
l
Hex C A F E B A B E
28 Table 7: Working out for Question 5-C University of Abertay

Question 6
a) 00101 + 5 +
10110 = 21 =
0 Carry 1
10 Carry 1
010 Carry 1
1010 Carry Nothing
-------
11010 Final Answer (Decimal 26)
=====

b) 100111 + 39 +
100101 37 =
0 Carry 1
00 Carry 1
100 Carry 1
1100 Carry Nothing
01100
001100 Carry 1
01001100 = Final Answer (Decimal 76)

3
As you can see from the table, row two’s text has to be reduced to such a small size it is impossible to see the
text. Large numbers like those presented here take far too much space to be practical.

David Gordon (1004103)


CE0714A
Question 7
The following calculations are done using 8bit, twos-compliment

a) 100 + 27
100 = 1110 0100
27 = 1001 1011
--- ---------
127 1
11
111
1111
1 1111
11 1111
111 1111
---------
1111 1111 Final Answer
=========

b) 84 + 52
84 = 1101 0100
52 = 1011 0100
--- ---------
136 0
00
000 Carry 1
1000
29 0 1000 Carry 1 University of Abertay
00 1000 Carry 1
000 1000 Carry 1
---------
1000 1000 Final Answer
=========

c) 115 – 64
115 = 1111 0011
64 = 0100 0000
--- ---------
51 1
11
011
0011
1 0011
11 0011
011 0011 Carry 1
---------
1011 0011 Final Answer
=========

David Gordon (1004103)


CE0714A
d) -85 – 44
-85 = 0101 0101
-44 = 0010 1100
--- ---------
-129

-129 is beyond the scale that 8bit twos-compliment allows, the lowest permissible value is -128. We
would need to use 16bit twos-compliment for this calculation if the machine being used could
process a 16bit value. Most current machines are capable of processing 32bit values with many
being able to process 64bit values.

Question 8

Question Hexadecimal Binary Decimal


a) FF 1111 1111 255
b) B0 1011 0000 176
c) 1212 0001 0010 0001 0010 4,626
d) FACE 1111 1010 1100 1110 64,206
30 University of Abertay
Table 8: Hexadecimal to Binary and Decimal Conversion

Binary Arithmetic
Having an understanding of binary allows us to visualise the mechanics behind how a computer
processes binary instructions to produce expected results. Processing binary to achieve a resultant
requires the manipulation of the binary input to get a correct output – this processing is done
through the two-state mathematics called Boolean algebra.

The two states are True or 1, and False, or 0; these states can be acted upon by a number of
operators.

Operator Name Commonly Displayed As Corresponding Circuit Name


NOT Ᾱ NOT GATE
AND AB AND GATE
OR A+B OR GATE
Table 9: Boolean algebra Description

The NOT operator can be combined with the AND operator, NAND, and the OR Operator, NOR.
There is also the exclusive directive which can be added to produce the XOR, XNOR directives. It is
customary to write logical operators and results in uppercase, such as TRUE, FALSE, AND, OR; this
assists in distinguishing logical expressions from Standard English wordage.

David Gordon (1004103)


CE0714A
Question 1) XOR Output
Input Output Ultimately in binary, each gate has two inputs and one output, and as
X Y X≠Y Boolean algebra is based upon a logical sequence of events the output
0 0 0
1 0 1 is always the same under the same circumstances. That is there is no
0 1 1 alternative output possible. The XOR gate for instance can receive as
1 1 0
input 0, 0; 1, 0; 0, 1; or 1, 1 each input combination provides a
guaranteed result, known as its truth table. As you can see from table 10, XOR returns, or outputs
True only when the inputs are not the same. So if only one input is at a logical
Table 10: XOR Truth Table
1 state – the output would be also at logical 1, or True.

Question 2 & 3a) NAND Output


Input Output Logically we can make assumptions about the input of a gate from its
X Y X↑Y output. If the output of a NAND gate was FALSE, 0, we could deduce
0 0 1
1 0 0 that the inputs are not both set to the logical state of FALSE.
0 1 0 Alternatively, if the output was TRUE or 1, then both inputs must have
1 1 0
been set to the logical state of FALSE, or 0.

31 Table 11: NAND Truth Table University of Abertay

Question 3b) NOT OR GATE

Figure 9: OR gate being fed by two NOT Inputs

A B NOT A NOT Q To generate the truth table we start at the Inputs, NOT them, and
B put the new values into the OR gate to calculate the results.
0 0 1 1 1
0 1 1 0 1
1 0 0 1 1 Table 12: Circuit Truth Table
1 1 0 0 0

David Gordon (1004103)


CE0714A
Question 3c) XOR AND OUTPUT

Figure 10: A Circuit with a XOR and AND Out puts

A B XOR A AND B S C
0 0 0 0 0 0
0 1 1 0 1 0
1 0 1 0 1 0
1 1 0 1 0 1
Table 13: : Circuit Truth Table

Question 4a) A AND NOT B GATE

32 University of Abertay

Figure 11: A AND NOT B Gate

A B AND A NOT B Q
0 0 0 1 0
0 1 0 0 0
1 0 0 1 0
1 1 1 0 0
Table 14: AND A NOT B Gate Truth Table

David Gordon (1004103)


CE0714A
Question 4b) A OR (B AND C) GATE

Figure 12: A OR (B AND C) Gate

A B C A OR B OR B AND C AND Q R
0 0 0 0 0 0 0 0 0
0 0 1 1 1 0 0 1 0
0 1 0 1 1 0 0 1 0
1 0 0 1 1 0 0 1 0
0 1 1 1 1 1 1 1 1
1 1 0 1 1 0 0 1 0
1 1 1 1 1 1 1 1 1
Table 15: : A OR (B AND C)

33 Question 4c) (A AND B) NOR (A AND C) GATE University of Abertay

Figure 13: (A AND B) NOR (A AND C) Gate

A B C OR A OR B AND A AND C Q R
0 0 0 0 0 0 0 0 0
0 0 1 1 0 0 1 0 0
0 1 0 1 1 0 0 1 0
1 0 0 1 0 1 0 1 0
1 0 1 1 0 1 1 1 1
1 1 0 1 1 1 0 1 0
1 1 1 1 1 1 1 1 1

David Gordon (1004103)


CE0714A
Table 16:: (A AND B) NOR (A AND C) Truth table

Question 5) Logic Expression

A B C X
0 0 0 0
0 0 1 0
0 1 0 1
0 1 1 1
1 0 0 1
1 0 1 1
1 1 0 0
1 1 1 0

Question 6) truth Table for Circuit in Question 5

34 University of Abertay

David Gordon (1004103)


CE0714A
Manipulating Bits and Bytes in C#
#region
/// David Gordon 1004103
/// Abertay University of Dundee
/// Computer Architecture and Operating Systems [CE0714A]
/// For Academic Purposes Only: All rights reserved 2010
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace COAS
{
class Program
{

// Convert to binary, then Convert to Byte


// Used in Question 2 - showing an alternative approach
static Byte binVal255 = Convert.ToByte(ConvertToBase(255, 2), 2);
static Byte binVal85 = Convert.ToByte(ConvertToBase(85, 2), 2);

static void Main(string[] args)


{
Question1();
35 Question2(); University of Abertay
Question3();
Question3b();
Question3c();
Question4();
Question5();
Question6();
Question7();

Console.ReadKey();
}

#region QUESTION1
/// <summary>
/// Output of Question 1
/// </summary>
private static void Question1()
{
Console.WriteLine("Decimal :{0} ", 255);
Console.WriteLine("Decimal :{0} ", 85);
Console.WriteLine("Binary :{0} ", ConvertToBase(255, 2));
Console.WriteLine("Binary :{0} ", ConvertToBase(85, 2));
Console.WriteLine("Hexidecimal:{0} ", ConvertToBase(255, 16));
Console.WriteLine("Hexidecimal:{0} ", ConvertToBase(85, 16));
}

#endregion

#region QUESTION2

David Gordon (1004103)


CE0714A
/// <summary>
/// Output For Question 2
/// </summary>
private static void Question2()
{
Console.WriteLine("Decimal : {0} ", binVal255 & binVal85);
Console.WriteLine("Binary : {0} ", ConvertToBase(binVal255
& binVal85, 2));
Console.WriteLine("Hexidecimal: {0} ", ConvertToBase(binVal255
& binVal85, 16));
}

#endregion

#region QUESTION3

/// <summary>
/// Output of question 3
/// </summary>
private static void Question3()
{
Console.WriteLine("0xFF AND 0x55: " + calculation3a());
}

#endregion

#region QUESTION3b
private static void Question3b()
{
// Write out the values
36 Console.WriteLine("NOT 0x18 Decimal : " + University of Abertay
HextoInt(ConvertToBase(~calculation3b(), 16)));
Console.WriteLine("NOT 0x18 Binary : " +
ConvertToBase(~calculation3b(), 2));
Console.WriteLine("NOT 0x18 Hexidecimal : " +
ConvertToBase(~calculation3b(), 16));
}

#endregion

#region QUESTION3c

private static void Question3c()


{
byte int85, int01, int15;
int85 = 0x85;
int01 = Convert.ToByte("01010101", 2);
int15 = 15;

byte res = (byte)(int85 | int01);


res = (byte)(res & int15);

Console.WriteLine("Decimal (0x85 OR 01010101b) AND 15 :


{0:D3}", res);
Console.WriteLine("Binary (0x85 OR 01010101b) AND 15 :
{0}", Convert.ToString(res, 2));
Console.WriteLine("Hexidecimal (0x85 OR 01010101b) AND 15 :
{0:X2}", res);
}
#endregion

David Gordon (1004103)


CE0714A
#region QUESTION4

private static void Question4()


{
// Convert everything to Binary
byte a, b, c, a2, b2, c2;
a = Convert.ToByte("01010101", 2);
a2 = Convert.ToByte("10101010", 2);
b = Convert.ToByte("01010101", 2);
b2 = Convert.ToByte("10101010", 2);
c = Convert.ToByte("01010101", 2);
c2 = Convert.ToByte("10101010", 2);

// Part A
if ((byte)(a & a2) != 0)
{
Console.WriteLine("A) 01010101 AND 10101010 = True");
}
else
{
Console.WriteLine("A) 01010101 AND 10101010 = False");
}

// Part B
if ((byte)(b | b2) != 0)
{
Console.WriteLine("B) 01010101 OR 10101010 = True");
}
else
{
37 Console.WriteLine("B) 01010101 OR 10101010 University
= False");
of Abertay
}

// Part C
if ((byte)(c ^ c2) != 0)
{
Console.WriteLine("C) 01010101 XOR 10101010 = True");
}
else
{
Console.WriteLine("C) 01010101 XOR 10101010 = False");
}

}
#endregion

#region QUESTION5
private static void Question5()
{
// Convert everything to Byte Binary
byte b0, b4, b6, b81;
b0 = 0;
b4 = 4;
b6 = 6;
b81 = 81;

#region AND OPERATIONS


if ( (byte) (b0 & b81) != 0)
{
Console.WriteLine("b0 & 81 = True");
}

David Gordon (1004103)


CE0714A
else
{
Console.WriteLine("b0 & 81 = False");
}

if ((byte)(b4 & b81) != 0)


{
Console.WriteLine("b4 & 81 = True");
}
else
{
Console.WriteLine("b4 & 81 = False");
}

if ((byte)(b6 & b81) != 0)


{
Console.WriteLine("b6 & 81 = True");
}
else
{
Console.WriteLine("b6 & 81 = False");
}
#endregion

#region OR OPERATIONS
if ((byte)(b0 | b81) != 0)
{
Console.WriteLine("b0 | 81 = True");
}
else
38 { University of Abertay
Console.WriteLine("b0 | 81 = False");
}

if ((byte)(b4 | b81) != 0)
{
Console.WriteLine("b4 | 81 = True");
}
else
{
Console.WriteLine("b4 | 81 = False");
}

if ((byte)(b6 | b81) != 0)
{
Console.WriteLine("b6 | 81 = True");
}
else
{
Console.WriteLine("b6 | 81 = False");
}
#endregion

#region XOR OPERATIONS


if ((byte)(b0 ^ b81) != 0)
{
Console.WriteLine("b0 ^ 81 = True");
}
else
{
Console.WriteLine("b0 ^ 81 = False");

David Gordon (1004103)


CE0714A
}

if ((byte)(b4 ^ b81) != 0)
{
Console.WriteLine("b4 ^ 81 = True");
}
else
{
Console.WriteLine("b4 ^ 81 = False");
}

if ((byte)(b6 ^ b81) != 0)
{
Console.WriteLine("b6 ^ 81 = True");
}
else
{
Console.WriteLine("b6 ^ 81 = False");
}
#endregion
}

#endregion

#region QUESTION6

// Add a variable “a” of type byte and set a = 127.


// (a) If you add 1 to a what will be the answer?
// (b) What will be the answer if a is of type sbyte and why?
private static void Question6()
39 { University of Abertay
byte a = 127;
Console.WriteLine("byte A = " + a);
a++;
Console.WriteLine("byte A + 1 = " + a);
// byte 0 to 255 Unsigned 8-bit integer System.Byte

sbyte aa = 127;
Console.WriteLine("sbyte A = " + aa);
aa++;
Console.WriteLine("sbyte A + 1 = " + aa);
// sbyte -128 to 127 Signed 8-bit integer
System.SByte
// Adding 1 to 127 sets the signed bit to - (Negative) -
therefore -128 is the result
}

#endregion

#region QUESTION7
//Multiply a byte by 4 without using * or +. What happens if the
value of the byte is greater than 63?

private static void Question7()


{
byte a = 10;
Console.WriteLine("A = " + a + " or in Binary " +
Convert.ToString(a,2));
a = (byte) (a << 2);
Console.WriteLine("A = " + a + " or in Binary " +
Convert.ToString(a, 2));

David Gordon (1004103)


CE0714A
byte aa = 64;
Console.WriteLine("A = " + aa + " or in Binary " +
Convert.ToString(aa, 2));
aa = (byte)(aa << 2);
Console.WriteLine("A = " + aa + " or in Binary " +
Convert.ToString(aa, 2));
// Final result too large for a byte - so a value of 0 is
returned
}
#endregion

#region Utilities
/// <summary>
/// Convert an Int to A Base X
/// </summary>
/// <param name="val">
/// Int value to Convert
/// </param>
/// <param name="Base">
/// Int Base to which to convert to (Presuming base 10 as input)
/// </param>
/// <returns>
/// String representation of the conversion of the Int
/// </returns>
static private string ConvertToBase(int val, int Base)
{
string Value = Convert.ToString(val, Base);
return Value.ToString().ToUpper();
}
40 University of Abertay
/// <summary>
/// Do Question 3a's calculations
/// </summary>
/// <returns>
/// Returns a string result
/// </returns>
static string calculation3a()
{
// Convert Hex to Int
Int32 decValueFF = Int32.Parse("FF",
System.Globalization.NumberStyles.HexNumber);
Int32 decValue55 = Int32.Parse("55",
System.Globalization.NumberStyles.HexNumber);

// Convert Int to Bin


Byte binValFF = Convert.ToByte(ConvertToBase(decValueFF, 2),
2);
Byte binVal55 = Convert.ToByte(ConvertToBase(decValue55, 2),
2);

// AND the two values


return ConvertToBase(binValFF & binVal55, 2);
}

/// <summary>
/// Do Question 3b's calculations
/// </summary>
/// <returns></returns>
static int calculation3b()
{

David Gordon (1004103)


CE0714A
// Convert Hex to Int
Int32 decValue18 = Int32.Parse("18",
System.Globalization.NumberStyles.HexNumber);

// Convert Int to Bin


Byte binVal18 = Convert.ToByte(ConvertToBase(decValue18, 2),
2);

return binVal18;
}

/// <summary>
/// Convert a Hex String to Int
/// </summary>
/// <param name="hex">
/// String
/// </param>
/// <returns>
/// Int
/// </returns>
static private int HextoInt(string hex)
{
return Convert.ToInt32(hex, 16);
}

#endregion

}
41 } University of Abertay

Output:
Decimal : 255
Decimal : 85
Binary : 11111111
Binary : 1010101
Hexadecimal : FF
Hexadecimal : 55
Decimal : 85
Binary : 1010101
Hexadecimal : 55
0xFF AND 0x55 : 1010101
NOT 0x18 Decimal : -25
NOT 0x18 Binary : 11111111111111111111111111100111
NOT 0x18 Hexidecimal : FFFFFFE7
Decimal (0x85 OR 01010101b) AND 15 : 005
Binary (0x85 OR 01010101b) AND 15 : 101
Hexidecimal (0x85 OR 01010101b) AND 15 : 05
A) 01010101 AND 10101010 = False
B) 01010101 OR 10101010 = True
C) 01010101 XOR 10101010 = True
b0 & 81 = False
b4 & 81 = False
b6 & 81 = False
b0 | 81 = True
b4 | 81 = True
b6 | 81 = True

David Gordon (1004103)


CE0714A
b0 ^ 81 = True
b4 ^ 81 = True
b6 ^ 81 = True
byte A = 127
byte A + 1 = 128
sbyte A = 127
sbyte A + 1 = -128
A = 10 or in Binary 1010
A = 40 or in Binary 101000
A = 64 or in Binary 1000000
A = 0 or in Binary 0

Notes on additional questions are located in the code.

Building Adders, Counters and Registers


Half Adder
The half adder circuit is the very simplest form
of addition. It has only two inputs which means
it can count to a maximum value of 2, or 0010b.
If we connect the outputs to two led, and the
input to simple off/ on switches – reproducing
binary 0, 1, we can build the half adder’s truth
42 table, via a test rig. University of Abertay

Figure 14: Half Adder Circuit Diagram

As we manipulate the input the LEDs output


should correspond to the bits that are being
switched on and off. Here 1b + 0b = 1b. This
can show us and prove the expected truth
table for the half-adder.

Figure 15: Half Adder’s Test Rig

A B S c Binary
0 0 0 0 0000b
0 1 1 0 0001b
1 0 1 0 0001b
1 1 1 1 0010b
Table 17: Half Adder Truth Table

David Gordon (1004103)


CE0714A
Full Adder
As we did with the half adder, we create a full adder by adding two half adders, as one half adder
feeds a second half adder’s input we do need to OR the output of the second half adder. From this a
test rig can be built which we can use to either create or prove a truth table.

Figure 16: Full Adder Circuit

43 Figure 17: Full Adder’s Test Rig University of Abertay

a b c q s Binary
0 0 0 0 0 0000b
0 0 1 1 0 0001b
0 1 0 1 0 0001b
0 1 1 0 1 0010b
1 0 0 0 1 0010b
1 0 1 1 1 0011b
1 1 1 0 1 0010b
Figure 18: Full Adder Truth Table

As the full adder has only two outputs it can only produce a maximum binary value of 0011b, or 3
decimal. Being based on binary it is relatively easy to see that combining two full adders one would
have a 2 bit adder, combining two 2 bit adders we would have a 4 bit adder ad infinitum.

David Gordon (1004103)


CE0714A
Bit Adder Example

Figure 19: 8 Bit adder based on 8 x Full Adders

44 University of Abertay

Figure 20: 8 Bit adder in operation

-ve edge triggered D-type flip-flop


A –ve edge triggered flip-flop is created from a Gated D-Latch. Thus complex components can be
created using very simple gates. Those combined gates can be combined with other collections to
make ever more complex instruction processors.

David Gordon (1004103)


CE0714A
A Flip-Flop life cycle
Figure 21: D-Type Flip-Flop

Figure 22: -ve Edge Triggered D-Type Flip-Flop

One can clearly see that the –ve Edge Triggered D-Type flip-flop is
composed of two D-Type Flip-Flops with the X1 input, put through a
NOT before becoming the input to the second D-Type Flip-Flop,
Stage 1: RS Flip-Flop
producing a Negative Edge flip-flop.

Stage 2: Clocked RS Flip-Flop

45 Stage 3: D-Type Flip-Flop University of Abertay

David Gordon (1004103)


CE0714A
4Bit Parallel Register

46 University of Abertay

Figure 23: 4Bit Parallel Register

Figure 24: 4 Bit Shift Register

David Gordon (1004103)


CE0714A
Figure 25: 4 Bit Up-Counter

Bits and PCs


A 2 – to – 4 line decoder converts a code into a set of signals. It is composed of two 1-to-2 line
decoders. Decoders have 2 input outputs. It is equivalent in use as the C language Switch statement.

47 University of Abertay

Figure 26: 2-to-4 Line Decoder

David Gordon (1004103)


CE0714A
Figure 27: 2-to-4 Line Decoder Test Rig

48 University of Abertay

Figure 28: 4-16 Line Decoder

David Gordon (1004103)


CE0714A
49 University of Abertay

Figure 29: 4-16 line Decoder Test Rig

Figure 30: 7 Segment LED Display Example

David Gordon (1004103)


CE0714A
Figure 31: 0 LED Display

Figure 32: 1 LED Display

50 University of Abertay

Figure 33: 2 LED Display

Figure 34: 3 LED Display

David Gordon (1004103)


CE0714A
Figure 35: 4 LED Display

Figure 36: 5 LED Display

51 University of Abertay

Figure 37: 6 LED Display

Figure 38: 7 LED Display

David Gordon (1004103)


CE0714A
Figure 39: 8 LED Display

Figure 40: 9 LED Display

52 University of Abertay

Figure 41: A LED Display

Figure 42: B LED Display

David Gordon (1004103)


CE0714A
Figure 43: C LED Display

Figure 44: D LED Display

53 University of Abertay

Figure 45: E LED Display

Figure 46: F LED Display

Controlling a seven segment LED is quick tricky and requires a number of components to be created
before the final circuit can be constructed. However, as always, one should never reinvent the
wheel. After beginning the design of a BCD Controller based upon the BCD to Seven segment
decoder logic diagram [ CITATION III87 \l 2057 ], I discovered a fully implemented controller with all

David Gordon (1004103)


CE0714A
sub-components already designed. I have simply used these [ CITATION aft10 \l 2057 ] to complete
the task.

54 University of Abertay
Figure 47: 7 Segment LED Controller 4

4
Completed Design by afterawe

David Gordon (1004103)


CE0714A
55 University of Abertay

Figure 48: BCD Controller

Figure 49: 7 Segment Display Controller

David Gordon (1004103)


CE0714A
56 University of Abertay

Figure 50: 8:1 Multiplexor

Figure 51: 4:1 Multiplexor

This provided enough information to generate a 0-9 display system; however, further investigation is
necessary to allow the display of the remaining six Hexadecimal values.

David Gordon (1004103)


CE0714A
Low-Level Programming
01first.asm - Arithmetic

Subtraction
; ===== WORK OUT 2 Minus 2 ======================================
CLO ; Close unwanted windows.
Division
MOV AL,2 ; Copy a 2 into the AL register.
MOV BL,2 ; Copy a 2 into the BL register.
SUB AL,BL ; Subtract AL to ;BL.
===== WORKgoes
Answer OUT into
2 Divided
AL. by 2 ====================================
END ; Program ends CLO ; Close unwanted windows.
MOV AL,2 ; Copy a 2 into the AL register.
; ===== Program Ends ===========================================
MOV CL,2 ; Copy a 2 into the CL register.
DIV AL,CL ; Divide AL by CL. Answer goes into AL.
END ; Program ends
; ===== Program Ends ===========================================

Divide by Zero
; ===== WORK OUT 2 Divided by 0 ==================================== As was expected the
CLO ; Close unwanted windows.
MOV CL,2 ; Copy a 2 into the CL register.
MOV DL,0 ; Copy a 2 into the DL register. software throws a
DIV AL,BL ; Divide CL by DL. Answer goes into CL.
END ; Program ends “Divide by Zero”
; ===== Program Ends ===========================================
Exception.

57 Multiplication University of Abertay

David Gordon (1004103)


CE0714A
; ===== WORK OUT 2 MULtiply by 2 ===================================
CLO ; Close unwanted windows.
MOV AL,2 ; Copy a 2 into the AL register.
MOV BL,2 ; Copy a 2 into the BL register.
MUL AL,BL ; MULtiply AL by BL. Answer goes into AL. 02tlight.asm -
END ; Program ends
; ===== Program Ends =========================================== Traffic Lights
; ===== CONTROL THE TRAFFIC LIGHTS =============================

CLO ; Close unwanted windows.


Start:
; Turn off all the traffic lights.
MOV AL,84 ; Copy 1000 0100 into the AL register.
OUT 01 ; Send AL to Port One (The traffic lights).
; Turn on Left Red - Right Green the traffic lights. 03move.asm -
MOV AL,C8 ; Copy 1100 1000 into the AL register. Data Moves
OUT 01 ; Send AL to Port One (The traffic lights).
; ---------------------------------------------------------------
; Turn on all the traffic lights.
; A program
MOV AL,30 to demonstrate
; Copy MOV commands.
0011 0000 into Mov is short for move.
the AL register.
OUT 01 ; Send AL to Port One (The traffic lights).
; ---------------------------------------------------------------
; Turn on all the traffic lights.
CLO ; Close unwanted windows.
; =====
MOV AL,58 IMMEDIATE MOVES
; Copy 0101 1000=====
into the AL register.
OUT 01 MOV
; SendAL,48 ; Copy
AL to Port One"H" HEXtraffic
(The into the AL register
lights).
MOV BL,45 ; Copy "E" HEX
; Turn on all the traffic into the BL register
lights.
MOV CL,4C ; Copy "L" HEX into the CL register
JMP Start MOV
; JumpDL,4C
back to; the
Copystart.
"L" HEX into the DL register
END ; Program ends.
; ===== INDIRECT MOVES =====
; ===== Program Ends MOV [C0],AL ; Copy value in AL to RAM location [C0] C0 = H
==========================================
MOV [C1],BL ; Copy value in BL to RAM location [C1] C1 = E
YOUR TASK MOV [C2],CL ; Copy value in CL to RAM location [C2] C2 = L
========= MOV [C3],DL ; Copy value in DL to RAM location [C3] C3 = L
MOV on AL,4F
Use the help page ; Copy
Hexadecimal and"O" HEX codes.
ASCII into the AL register
Work out what MOV [C4],AL
hexadecimal ; Copywill
numbers value in AL to
activate theRAM location [C4] C4 = O
correct traffic lights. Modify the program to step
the lights through a realistic sequence.
; ===== REGISTER INDIRECT MOVES =====
LEFT RIGHT MOV [CL],AL
BIN ; Copy theHEXvalue in AL to the RAM
; location that CL points to.
RAGR AGxx
58 RED GREEN MOV BL,[CL] ; Copy the
1000 0100 84 RAM location that CL pointsUniversity of Abertay
REDAMBER AMBER ; to into C8
1100 1000 the BL register.
GREEN RED 0011 0000 30
AMBER REDAMBER 0101 1000 58
END
; ---------------------------------------------------------------
TASK
====
Look up the ASCII codes of the letters in H (0x47),E (0x45),L (0x4C),L (0x4C),O (0x4F)
and move
these ASCII codes to RAM addresses [C0], [C1], [C2], [C3]
and [C4]. Run the program and watch how the text appears on
the simulated VDU display. This is very much the same as what
happens in the IBM PC running MS DOS. The program you write
should work but if you continue to study low level programming,
you will find much more efficient and flexible ways of solving
this problem.

04IncJmp.asm - Counting
; ====== Subtract 1 from the previous value in BL
MOV BL,40 ; Set BL to 40

Rep1: ; Repeat this sectio ; ====== ADD 3 to Total


DEC BL ; Subtract 1 from BL MOV BL,1 ; Set BL to 1
JMP Rep1 ; Repeat the loop
END ; End the program Rep1: ; Repeat this sectio
; ===== Program Ends =============================== ADD BL,3 ; Add 3 to BL
JMP sequence
; ===== Counting Fibonacci Rep1 of;numbers
Repeat the loop
=====================
END ; End the program
; ===== Program Ends ===============================
MOV BL,0 ; Initial value stored in BL = 0
MOV CL,1 ; Initial value stored in CL = 0
MOV DL,0 ; The Result
; ===== MULTIPLYING BY TWO Rep: ; Jump back to this label
MOV BL,1 ; Set BL to 1
ADD BL,CL ; ADD CL to BL (0 + 0) (0 + 1) (1 + 2) (2 + 3)
Rep1: ; Repeat this sectio PUSH BL
MUL BL,2 ; Multiply BL by 2 POP DL ; DL now equals the sum of BL + CL
JMP Rep1 ; Repeat the loop PUSH CL
END ; End the program POP BL ; BL Now Equals CL
; ===== Program Ends ===============================
PUSH DL
POP CL ; CL now equals the Previous SUM of BL + CL
David Gordon (1004103)
JMP Rep ; Jump back to Rep
CE0714A
END ; Program Ends

; ===== Program Ends ===============================


05keyb-in.asm
Easy! Display each character at the top left position of the VDU by copying them all to address [C0].

; --------------------------------------------------------------
; Input key presses from the keyboard until Enter is pressed.
; --------------------------------------------------------------
CLO ; Close unwanted windows.
Rep:
IN 00 ; Wait for key press - Store it in AL.
CMP AL,0D ; Was it the Enter key? (ASCII 0D)
MOV [C0],AL ; Copy the Character in AL to top left of the Video Memory (Screen)
JNZ Rep ; No - jump back. Yes - end.

END
; --------------------------------------------------------------

Harder Use BL to point to address [C0] and increment BL after each key press in order to see the
text as you type it.

; --------------------------------------------------------------
; Input key presses from the keyboard until Enter is pressed.
; --------------------------------------------------------------
CLO ; Close unwanted windows. Harder! Store all
MOV BL,C0 ; Copy C0 – Hex to BL
Rep: the text you type
IN 00 ; Wait for key press - Store it in AL.
CMP AL,0D ; Was it the Enter key? (ASCII 0D) in RAM when you
MOV [BL], AL ; Copy the Contents of AL to the Video Location BL
INC BL ; Move the Video Address on one place type it in.
JNZ Rep ; No - jump back. Yes - end.
When you
END
; -------------------------------------------------------------- press Enter,
59 University
display of
theAbertay
stored
text on the VDU display.

David Gordon (1004103)


CE0714A
; --------------------------------------------------------------
; A program to read in a string of text and store it in RAM.
; The end of text will be labelled with ASCII code zero/null.
; --------------------------------------------------------------
; THE MAIN PROGRAM
MOV BL,70 ; [70] is the address where the text will
; be stored. The procedure uses this.

CALL 10 ; The procedure at [10] reads in text and


; places it starting from the address
; in BL.

; BL should still contain [70] here.

CALL 40 ; This procedure does nothing until you


; write it. It should display the text.

HALT ; DON'T USE END HERE BY MISTAKE.


; --------------------------------------------------------------
; A PROCEDURE TO READ IN THE TEXT
ORG 10 ; Code starts from address [10]

PUSH AL ; Save AL onto the stack


PUSH BL ; Save BL onto the stack
PUSHF ; Save the CPU flags onto the stack

Rep:
IN 00 ; Input from port 00 (keyboard)
CMP AL,0D ; Was key press the Enter key?
JZ Stop ; If yes then jump to Stop
MOV [BL],AL ; Copy keypress to RAM at position [BL]
INC BL ; BL points to the next location.
JMP Rep ; Jump back to get the next character

Stop:
MOV AL,0 ; This is the NULL end marker
MOV [BL],AL ; Copy NULL character to this position.

POPF ; Restore flags from the stack


POP BL ; Restore BL from the stack
POP AL ; Restore AL from the stack

RET ; Return from the procedure.


60 ; -------------------------------------------------------------- University of Abertay
; A PROCEDURE TO DISPLAY TEXT ON THE SIMULATED SCREEN
ORG 40 ; Code starts from address [10]
MOV CL,C0 ; Copy VDU 0,0 Hex Address to CL
MOV BL,70 ; Set BL to memory location 70

Again:
MOV AL,[BL] ; Copy Memory contents to AL
CMP AL,0 ; End of message (NULL Marker) Found
JZ Bottom ; If Found go to Bottom
MOV [CL],AL ; copy AL contents to Screen location CL
INC CL ; Move the cursor on 1 place on VDU
INC BL ; Goto the next memory location
JMP Again ; Repeat the process

Bottom:
RET ; At present this procedure does
; nothing other than return.

; --------------------------------------------------------------
END ; It is correct to use END at the end.
; --------------------------------------------------------------
Difficult Type in text and store it. When Enter is pressed, display it on
the VDU screen in reverse order. Using the stack makes this task easier.

David Gordon (1004103)


CE0714A
; --------------------------------------------------------------
; A program to read in a string of text and store it on the Stack.
; The end of text will be labelled with ASCII code zero/null.
; Then printed out in reverse order on the console.
; --------------------------------------------------------------
; THE MAIN PROGRAM
CALL 10 ; The procedure at [10] reads in text and
; places it starting from the address
; in BL.

HALT ; DON'T USE END HERE BY MISTAKE.


; --------------------------------------------------------------
; A PROCEDURE TO READ IN THE TEXT
ORG 10 ; Code starts from address [10]
MOV DL,2 ; Add 2 to counter for the NULL and CR/LF Keys

Rep:
IN 00 ; Input from port 00 (keyboard)
CMP AL,0D ; Was key press the Enter key?
JZ Stop ; If yes then jump to Stop
PUSH AL ; Copy keypress to STACK LIFO
INC DL ; Count how many characters were entered
JMP Rep ; Jump back to get the next character

Stop:
MOV AL,0 ; This is the NULL end marker
PUSH AL ; Copy NULL character Stack.

CALL 40
RET ; Return from the procedure.
; --------------------------------------------------------------
; A PROCEDURE TO DISPLAY TEXT ON THE SIMULATED SCREEN
ORG 40 ; Code starts from address [10]
61 MOV CL,C0 ; Copy VDU 0,0 Hex Address to CL University of Abertay

Again:
CMP DL,0 ; If We have done all the chars end
JZ Bottom ; Go to end if done
POP BL ; Copy Memory contents to AL
CMP BL,0 ; Is this the Null Character?
JZ SKIP
CMP BL,27 ; Is this the LF/CR (Return / Enter Key)?
JZ SKIP
MOV [CL],BL ; Copy the char in BL into the VDU location
INC CL ; Move the VDU location on one place
SKIP: ; Skip the displaying of a character!
DEC DL ; Decrease the Character Counter
JMP Again ; Repeat the process

Bottom:
RET ; At present this procedure does
; nothing other than return.

; --------------------------------------------------------------
END ; It is correct to use END at the end.
; --------------------------------------------------------------

06proc.asm
Re-do the traffic lights program and use this procedure to set up realistic
time delays. 02tlight.asm

David Gordon (1004103)


CE0714A
; ---------------------------------------------------------------

; Traffic Lights with Time Delay


Re-do the
;
text input
;------ The Main Program ---------------------------------------- and display
CLO ; Close unwanted windows. program with
Start: procedures.
; Turn off all the traffic lights. Use one
MOV AL,84 ; Copy 1000 0100 into the AL register.
OUT 01 ; Send AL to Port One (The traffic lights). procedure to
; Turn on Left Red - Right Green the traffic lights. input the
CALL 40 ; Wait a bit text and one
MOV AL,C8 ; Copy 1100 1000 into the AL register. to display
OUT 01 ; Send AL to Port One (The traffic lights). it.
CALL 40 ; Wait a bit

MOV AL,30 ; Copy 0011 0000 into the AL register.


OUT 01 ; Send AL to Port One (The traffic lights).
CALL 40 ; Get input from the keypboard
; Wait a bit
; Display it on the console
MOV AL,58 ; Copy 0101; 1000
Usinginto
Routines
the AL register.
OUT 01 ; Send BL to Port One (The traffic lights).
CALL 40 ;------ The Main Program ----------------------------------------
; Wait a bit
CLO ; Close unwanted windows.
JMP Start ; Jump back to the start.
HALT ; --------------------------------------------------------------
; Program ends.
; Input key presses from the keyboard until Enter is pressed.
; --------------------------------------------------------------
CLO
; ----- Time Delay Procedure Stored At Address ; Close unwanted windows.
[40] -------------
ORG 40 ; Generate machineMOV BL,C0
code from ; Copy
address C0 - Hex to BL
[40]
CALL 30 ; Call Get Input Routine
PUSH BL HALT
; Save AL on the stack. ; End the program
PUSHF ; Save the CPU flags on the stack.
MOV ; GET
BL,10 ; The Duration of INPUT ---------------------------------------------------------
the delay
Rep: ORG 30
DEC BL ; Subtract Rep:
one from BL.
JNZ REP ; Jump back to RepIN 00 not ;Zero.
if BL was Wait for key press - Store it in AL.
CMP AL,0D ; Was it the Enter key? (ASCII 0D)
POPF ; Restore the CPU JZ ENDDthe ;stack.
flags from Yes - end.
62 POP BL ; Restore BL from CALL 40
the stack. University
; Call Display Output of Abertay
Routine
JMP Rep ; Repeat the process
RET ENDD:
; Return from the procedure.
RET ; Reurn from the routine
; ---------------------------------------------------------------
END
; DISPLAY OUTPUT ----------------------------------------------------
; ---------------------------------------------------------------
ORG 40

MOV [BL], AL ; Copy the Contents of AL to the Video Location BL


INC BL ; Move the Video Address on one place
RET ; return from the routine

END ; EXIT
; --------------------------------------------------------------

David Gordon (1004103)


CE0714A
07textio.asm
TASK

17) Write a program using three procedures. The first should read text from the keyboard and
store it in RAM. The second should convert any upper case characters in the stored text to lower
case. The third should display the text on the VDU screen.

63 University of Abertay

David Gordon (1004103)


CE0714A
; --------------------------------------------------------------
; A program to read in a string of text and store it in RAM.
; The end of text will be labelled with ASCII code zero/null.
; --------------------------------------------------------------
; THE MAIN PROGRAM
MOV BL,A0 ; [A0] is the address where the text will
; be stored. The procedure uses this.

CALL 10 ; The procedure at [10] reads in text and


; places it starting from the address
; in BL.

CALL 40 ; Convert Uppercase to Lowercase

CALL 70 ; This procedure does nothing until you


; write it. It should display the text.

HALT ; DON'T USE END HERE BY MISTAKE.


; --------------------------------------------------------------
; A PROCEDURE TO READ IN THE TEXT
ORG 10 ; Code starts from address [10]

Rep:
IN 00 ; Input from port 00 (keyboard)
CMP AL,0D ; Was key press the Enter key?
JZ Stop ; If yes then jump to Stop
MOV [BL],AL ; Copy keypress to RAM at position [BL]
INC BL ; BL points to the next location.
JMP Rep ; Jump back to get the next character

Stop:
MOV AL,0 ; This is the NULL end marker
MOV [BL],AL ; Copy NULL character to this position.

RET ; Return from the procedure.

; --------------------------------------------------------------
; A PROCEDURE TO CONVERT UPPERCASE TEXT TO LOWERCASE
ORG 40 ; This routine is at address 40
MOV BL,A0 ; Go to beginning of the RAM
REP2:
MOV AL,[BL] ; Get char from RAM
CMP AL,0 ; Is it Null END OF LINE MARKER?
64 JZ BOT ; Go To BOT We are done here! University of Abertay
OR AL,20 ; OR MASK 0010 0000 (the difference between Upper and Lowercase)
MOV [BL],AL ; Save the lowecase letter back
INC BL ; Go to next RAM character
JMP REP2 ; Do next character

BOT:
RET ; Return from the Routine
; --------------------------------------------------------------
; A PROCEDURE TO DISPLAY TEXT ON THE SIMULATED SCREEN
ORG 70 ; Code starts from address [10]
MOV CL,C0 ; Copy VDU 0,0 Hex Address to CL
MOV BL,A0 ; Set BL to memory location A0

Again:
MOV AL,[BL] ; Copy Memory contents to AL
CMP AL,0 ; End of message (NULL Marker) Found
JZ Bottom ; If Found go to Bottom
MOV [CL],AL ; copy AL contents to Screen location CL
INC CL ; Move the cursor on 1 place on VDU
INC BL ; Goto the next memory location
JMP Again ; Repeat the process

Bottom:
RET ; At present this procedure does
; nothing other than return.

; --------------------------------------------------------------
END ; It is correct to use END at the end.
; --------------------------------------------------------------
18) Improve the traffic lights data table so there is an overlap with
both sets of lights on red.

David Gordon (1004103)


CE0714A
; ----- EXAMPLE 8 ------- DATA TABLES --------------------------
JMP Start ; Skip past the data table.

DB 84 ; Data table begins. (RED AND GREEN)


DB C8 ; These values control the traffic lights (RED AMBER AND AMBER)
DB D0 ; Both reds on temporarily (RED AMBER AND RED)
DB 31 ; This sequence is simplified. (GREEN AND RED)
DB 58 ; Last entry is also used as end marker (AMBER AND RED AMBER)
DB 98 ; Last entry is also used as end marker (RED AND RED AMBER)
; ----- EXAMPLE 8 ------- DATA TABLES --------------------------
Start:
MOV
JMP BL,02
Start ; 02 ispast
; Skip start
the address of data table
data table.
Rep:
MOV
DB AL,[BL]; Reset ;the
FF Copy data from table to AL
snake
DB
OUT 4F
01 ;
; Down MAX from
Output MovesAL register to port 01
DB 4F ;
DB
CMP 4F
AL,98 ;
; Last item in data table ???
DB 4F ;
JZ
DB Start
4F ;
; If yes then jump to Start
INC
DB BL
4F ;
; In no then point BL to the next entry
JMP
DB Rep
4F ;
; Jump back to do next table entry
DB 4F ;
END
DB 4F ;
DB 4F ;
; --------------------------------------------------------------
DB 47 ; DOWN HALF MAX DISTANCE
DB 1F ; RIGHT MAX DISTANCE
DB 1F ; RIGHT MAX DISTANCE
DB 1F ; RIGHT MAX DISTANCE
DB 8F ; UP MAX DISTANCE 19) Use a data
DB 8F ; UP MAX DISTANCE
DB 8F ; UP MAX DISTANCE table to navigate the
DB 8F ; UP MAX DISTANCE snake through the
DB 1F ; RIGHT MAX DISTANCE
DB 1F ; RIGHT MAX DISTANCE maze. This is on port
DB 1F ; RIGHT MAX DISTANCE 4. Send FF to the
DB 4F ; Down MAX DISTANCE snake to reset it. Up,
DB 4F ; Down MAX DISTANCE
DB 4F ; Down MAX DISTANCE down left and right
DB 4F ; Down MAX DISTANCE are controlled by the
DB 1F ; RIGHT MAX DISTANCE
DB 1F ; RIGHT MAX DISTANCE left four bits. The
65 DB 8F ; UP MAX DISTANCE right University
fourof Abertay
bits
DB 8F ; UP MAX DISTANCE control the distance
DB 8F ; UP MAX DISTANCE
DB 8F ; UP MAX DISTANCE moved.
DB 8F ; UP MAX DISTANCE
DB 8F ; UP MAX DISTANCE
DB 8F ; UP MAX DISTANCE
DB 8F ; UP MAX DISTANCE
DB 2F ; LEFT MAX DISTANCE
DB 2F ; LEFT MAX DISTANCE 20) Write a
DB 2F ; LEFT MAX DISTANCE program to spin the
DB 2F ; LEFT MAX DISTANCE
DB 2F ; LEFT MAX DISTANCE stepper motor.
DB 2F ; LEFT MAX DISTANCE Activate bits 1, 2, 4
DB 8F ; UP MAX DISTANCE
DB 8F ; UP MAX DISTANCE and 8 in sequence to
DB 8F ; UP MAX DISTANCE energise the
DB 1F ; RIGHT MAX DISTANCE electromagnets in
DB 1F ; RIGHT MAX DISTANCE
DB 1F ; RIGHT MAX DISTANCE turn. The motor can be
DB 1F ; RIGHT MAX DISTANCE half stepped by
DB 1F ; RIGHT MAX DISTANCE
DB 1F ; RIGHT MAX DISTANCE turning on pairs of
DB 1F ; RIGHT MAX DISTANCE magnets followed by a
DB 1F ; RIGHT MAX DISTANCE
DB 4F ; Down MAX Moves single magnet followed
DB 4F ; by a pair and so on.
DB 4F ;
DB 4F ;
DB 4F ; ; ----- EXAMPLE 8 ------- DATA TABLES --------------------------
DB 4F ;
DB 4F ; JMP Start ; Skip past the data table.
DB 4F ;
DB 4F ; DB 1 ; Activate Elctro Magnet 1
DB 4F ; DB 2 ; Activate Elctro Magnet 2
DB 4F ; DB 4 ; Activate Elctro Magnet 4 (next is 8)
DB 4A ; STOP A LITTLE SHORT OF MAXDBDISTANCE
8 ; Last entry is also used as end marker

DB 58 ; Last entry is also Start:


used as end marker
MOV BL,02 ; 02 is start address of data table
Start: Rep:
MOV BL,02 ; 02 is start address of data MOVtable AL,[BL] ; Copy data from table to AL
Rep: OUT 05 ; Output from AL register to port 01
MOV AL,[BL] ; Copy data from table to AL
OUT 04 ; Output from AL register toCMP
port 01AL,8 ; Last item in data table ???
David Gordon (1004103) JZ
INC
Start ; If yes then jump to Start
BL ; In no then point BL to the next entry
CMP AL,58 ; Last item in data table ???
JZ Start ; If yes then jump to Start JMP Rep ; Jump back to do next table entry
INC BL ; In no then point BL to the next entry CE0714A
JMP Rep ; Jump back to do next tableEND
entry
; --------------------------------------------------------------
END
21) Use a data table to make the motor perform a complex sequence of
forward and reverse moves. This is the type of control needed in robotic
systems, printers and plotters. For this exercise, it does not matter
exactly what the motor does.

; ----- EXAMPLE 8 ------- DATA TABLES --------------------------

JMP Start ; Skip past the data table.


09param.asm
22) Write
DB 1 ; Activate Elctro Magnet 1 a procedure
DB 2 ; Activate Elctro Magnet 2 that doubles a
DB 4 ; Activate Elctro Magnet 4
number. Pass
DB 4 ; Activate Elctro Magnet 4 the single
DB 2 ; Activate Elctro Magnet 2 parameter into
DB 1 ; Activate Elctro Magnet 1
the procedure
DB 2 ; Activate Elctro Magnet 2 using a
DB 4 ; Activate Elctro Magnet 4 (next is 8) register. Use
DB 8 ; Last entry is also used as end marker the same
register to
Start: return the
MOV BL,02 ; 02 is start address of data table result.
Rep:
MOV AL,[BL] ; Copy data from table to AL
OUT 05 ; Output ;from
-----ALEXAMPLE 9 -------
register Passing
to port 01 Parameters -------------------
; ----- Use Registers to pass parameters into a procedure ------
CMP AL,8 ; Last item in data table ???
JZ Start ; If yes then jump
JMP to Start
Start ; Skip over bytes used for data storage
INC BL ; In no then point BL to the next entry
JMP Rep ; Jump back to do next table entry
Start:
MOV AL,5
END CALL 30 ; A procedure to Double AL Value
; Result returned in AL.
; --------------------------------------------------------------
; ----- A procedure to Double a Number held in AL -------------------------
66 ; Parameters passed into procedure University of Abertay
using AL and BL
; Result returned in AL
23) Write a procedure ; This method is simple but is no good if there are a
; lot of parameters to be passed.
to invert all the bits in
a byte. All the zeros ORG 30 ; Code starts at address [30]
should become ones. All MUL AL,2 ; Do the Multiplication. Result goes into AL
the ones should become
zeros. Pass the value to RET ; Return from the procedure
be processed into the ; --------------------------------------------------------------
procedure using a RAM END
location. Return the
result in the same RAM
location.

; ----- EXAMPLE 9 ------- Passing Parameters -------------------


; Start Value 10100101b = 0xA5 24) Write
; Result 1011010b = 0x5A
; ----- Use Registers to pass parameters into a procedure ------ a procedure
that works
JMP Start ; Skip over bytes used for data storage
DB 0 ; Reserve a byte of RAM at address [02] out Factorial
Start: N. This
MOV AL,A5 ; AL = 10100101b example shows
MOV [02],AL ; Store 10100101b into address [02]
CALL 40 one method
for working
; ----- A procedure to Double a Number held in AL ------------------------- out factorial
N. Factorial
; Parameters passed into procedure using AL and BL
; Result returned in AL 5 is 5 * 4 *
; This method is simple but is no good if there are a
; lot of parameters to be passed.

ORG 40 ; Code starts at address [30]

NOT AL ; FLIP the Bits in 10100101b and


; MAKE AL = the new result
David Gordon
MOV (1004103)
[02],AL ;Store result in 02

RET ; Return from the procedure


CE0714A
; --------------------------------------------------------------
END
3 * 2 * 1 = 120. Your procedure should work properly for factorial 1, 2,
3, 4 or 5.
Factorial 6 would cause an overflow. Use the stack to pass parameters and
return the result. Calculate the result. Using a look up table is
cheating!

; ----- EXAMPLE 9 ------- Passing Parameters -------------------


; Calculate the Factorial of 5
; ----- Use Registers to pass parameters into a procedure ------
25) Write
JMP Start ; Skip over bytes used for data storage
a
Start: procedure
MOV AL,5 ; AL = 5 that
PUSH AL ; Throw it on the stack
CALL 40 ; Call the routine to calculate the factorial works out
Factorial
; ----- A procedure to Double a Number held in AL ------------------------- N. Use
the
ORG 40 ; Code starts at address [40] stack
POP BL ; IGNORE THE STACK FOR CALL 40
POP BL ; BL now = 5 for
PUSH BL ; CL Will be the counter parameter
POP CL
DEC CL ; First Multiplication is one less than starting number passing.
REP: Write a
CMP CL,0 ;
JZ ENDD ; If counted to zero leave recursive
MUL BL,CL ; Multiply CL by the counter
DEC CL ; Reduce the counter by 1
JMP REP

ENDD:
PUSH BL ; This is the answer put it on the stack for later POPing
RET ; Return from the procedure

; --------------------------------------------------------------
END
67 ; ---- University of Abertay
ALTERNATIVELY RECURSION COULD HAVE BEEN USED.
procedure. Use this definition of Factorial.

Factorial ( 0 ) is defined as 1.
Factorial ( N ) is defined as N * Factorial (N - 1).

To work out Factorial (N), the procedure first tests to see


if N is zero and if not then re-uses itself to work out
N * Factorial (N - 1). This problem is hard to understand
in any programming language. In assembly code it is
harder still.

; RECURSIVE FACTORIAL CALCULATOR

Start: 10swint.asm
MOV AL,5 ; AL = 5, the number to factorise.
PUSH AL ; Throw it on the stack
CALL 40 ; Call the ROUTINE at Address 40 26) Write a new
HALT ; STOP THE PROGRAM
interrupt 02 that
;------------------------------- fetches a key press
; THE RECURSIVE FACTORIAL ROUTINE from the keyboard and
ORG 40 ; THE FACTORISING ROUTINE (RECURSIVE)
POP BL ; IGNORE THE STACK FOR THE CALL 40 stores it into RAM.
POP BL ; GET THE COUNTER and put it in BL The IBM PC allocates
DEC BL ; One too many so reduce the counter by one
CMP BL,1 ; Stop if Counter = 1 16 bytes for key
JZ BOT press storage. The
MUL AL,BL ; Multiply CL by the Counter
PUSH BL ; Throw the counter on the stack 16 locations are used
CALL 40 ; CALL SELF (Recursion) in a circular
BOT:
fashion.
RET

END
David Gordon (1004103)
CE0714A
; --------------------------------------------------------------
; An example of software interrupts.
; --------------------------------------------------------------
JMP Start ; Jump past table of interrupt vectors 27) Create a new
DB 51 ; Vector at 02 pointing to address 51
interrupt that puts
Start: characters onto the
next free screen
INT 02 ; Do interrupt 02
JMP Start location. See if you
; -------------------------------------------------------------- can get correct
ORG 50 behaviour in response
DB E0 ; Data byte - could be a whole table here to the Enter key being
; Interrupt code starts here pressed (fairly easy)
MOV CL,40 ; [40] is the address where the text will
PUSH AL ; Save AL onto the stack and if the Back Space
PUSH CL ; Save CL onto the stack key is pressed
PUSHF ; Save the CPU flags onto the stack
(harder).
Rep:
IN 00 ; Input from port 00 (keyboard)
CMP AL,0D ; Was key press the Enter key?
JZ Stop ; If yes then jump to Stop
MOV [CL],AL ; Copy keypress to RAM at position [CL]
INC CL ; CL points to the next location.
JMP Rep ; Jump back to get the next character

Stop:
MOV AL,0 ; This is the NULL end marker A Comparison of
MOV [CL],AL ; Copy NULL character to this position.

POPF ; Restore flags from the stack


Low and High Level
POP CL ; Restore CL from the stack
POP AL ; Restore AL from the stack Languages
IRET
; --------------------------------------------------------------
; --------------------------------------------------------------
END
; --------------------------------------------------------------

68 University of Abertay

David Gordon (1004103)


CE0714A
Error Detection

69 University of Abertay

David Gordon (1004103)


CE0714A
References

ANONYMOUS. 2010. 10/100 Mbps PCI Network Card. [online]. [Accessed 11 Dec 2010]. Available
from World Wide Web: <http://www.usr.com/products/networking/networking-product.asp?
type=specs&sku=USR997900>

ANONYMOUS. 2010. Comprehensive List of How (Key to Press) to Access BIOS for Various OEM and
Computer Systems. [online]. [Accessed 11 Dec 2010]. Available from World Wide Web:
<http://www.mydigitallife.info/2008/07/06/comprehensive-list-of-how-key-to-press-to-access-bios-
for-various-oem-and-computer-systems/>

CONSORTIUM, Unicode. 2010. C0 Controls and Basic Latin (PDF). [online]. [Accessed 13 Dec 2010].
Available from World Wide Web: <http://www.unicode.org/charts/PDF/U0000.pdf>

III, Forrest M. Mims. 1987. Diagram.Com. [online]. [Accessed 22 Dec 2010]. Available from World
Wide Web: <http://thediagram.com/7_2/bcd_decoder.html>

NIRMAL. 2009. Windows OS Version Numbers. [online]. [Accessed 11 Dec 2010]. Available from
World Wide Web: <http://www.nirmaltv.com/2009/08/17/windows-os-version-numbers/>
70 University of Abertay
QUILLEY, Andrew. 2010. IT Jargon Buster. [online]. [Accessed 10 Dec 2010]. Available from World
Wide Web: <http://www.it-station.co.uk/jargon.html#c>

RICKER, Thomas. 2009. Tilera's 100-core Tile-GX processor won't boil the oceans, will still melt faces.
[online]. [Accessed 10 Dec 2010]. Available from World Wide Web:
<http://www.engadget.com/2009/10/26/tileras-100-core-tile-gx-processor-wont-boil-the-oceans-
will/>

David Gordon (1004103)


CE0714A
71 University of Abertay

David Gordon (1004103)


CE0714A

You might also like