caos - portfolio 2010 - 2011

78
Abertay University Compung 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 Operang Systems Assessment Due Date: 10/01/2011 Module Tutor: Dr I Ferguson Declaraon 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

Upload: dave-gordon

Post on 04-Apr-2015

101 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: CAOS - Portfolio 2010 - 2011

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

Page 2: CAOS - Portfolio 2010 - 2011

2University of Abertay

CE0714A

Computer Architecture and Operating Systems

David Gordon

1004103

First Year Portfolio

University of Abertay

B.Sc. Digital Forensics

2010 - 2011

Page 3: CAOS - Portfolio 2010 - 2011

3University of Abertay

CE0714A

AbstractThe 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.

AcknowledgementsAll trademarks and names are owned and copyrighted by their respective owners.

The contents of this document are for educational purposes only.

Page 4: CAOS - Portfolio 2010 - 2011

4University of Abertay

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

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

Page 5: CAOS - Portfolio 2010 - 2011

5University of Abertay

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

Error Detection....................................................................................................................................45

References...........................................................................................................................................46

Page 6: CAOS - Portfolio 2010 - 2011

6University of Abertay

CE0714A

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

Page 7: CAOS - Portfolio 2010 - 2011

7University of Abertay

CE0714A

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

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

Page 8: CAOS - Portfolio 2010 - 2011

8University of Abertay

CE0714A

Hardware FamiliarisationDigital 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

The MotherboardThe 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

Page 9: CAOS - Portfolio 2010 - 2011

9University of Abertay

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.

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

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

Chipset

Figure 2: Motherboard serial number

Page 10: CAOS - Portfolio 2010 - 2011

10University of Abertay

CE0714A

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

VIA VT1708B HD Audio Codec  with 6-Channel

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

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)

Page 11: CAOS - Portfolio 2010 - 2011

11University of Abertay

CE0714A

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

department if it is required for a digital forensic investigation.

Page 12: CAOS - Portfolio 2010 - 2011

12University of Abertay

CE0714A

The Central Processing UnitThe CPU is often referred to as the “brain” (QUILLEY, Andrew, 2010) 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 (RICKER, Thomas, 2009).

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

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

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)

EssentialsStatus LaunchedLaunch Date Q3'08Processor Number Q9650# of Cores 4# of Threads 4Clock Speed 3 GHzL2 Cache 12 MBBus/Core Ratio 9FSB Speed 1333 MHzFSB Parity No

Figure 3: Quad Core Intel CPU

Page 13: CAOS - Portfolio 2010 - 2011

13University of Abertay

CE0714A

Instruction Set 64-bitEmbedded Options Available NoSupplemental SKU NoLithography 45 nmMax TDP 95 WVID Voltage Range 0.8500V-1.3625VTray 1ku Budgetary Price $316.00Package SpecificationsTCASE 71.4°CPackage Size 37.5mm x 37.5mmProcessing Die Size 214 mm2

# of Processing Die Transistors 820 millionSockets Supported LGA775Halogen Free Options Available Yes

Advanced TechnologiesIntel® Turbo Boost Technology NoIntel® Hyper-Threading Technology NoIntel® Virtualization Technology (VT-x) YesIntel® Virtualization Technology for Directed I/O (VT-d) YesIntel® Trusted Execution Technology YesAES New Instructions NoIntel® 64 YesIdle States YesEnhanced Intel SpeedStep® Technology YesIntel® Demand Based Switching NoThermal Monitoring Technologies YesExecute Disable Bit Yes

Page 14: CAOS - Portfolio 2010 - 2011

14University of Abertay

CE0714A

Random Access MemoryThe 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

damage comes to the RAM.

Product P/N: TS512MLK72V3N

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

Figure 4: Transcend DDR3 Memory

Page 15: CAOS - Portfolio 2010 - 2011

15University of Abertay

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.

Hard disks can be external as well as internal, that is they can be readily attached 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 SpecificationsTransfer Rates

Buffer To Host (Serial ATA) 3 Gb/s (Max)

Physical SpecificationsFormatted Capacity 2,000,398 MBCapacity 2 TBInterface SATA 3 Gb/sUser Sectors Per Drive 3,907,029,168

Page 16: CAOS - Portfolio 2010 - 2011

16University of Abertay

CE0714A

Physical DimensionsEnglish

Height 1.028 InchesLength 5.787 InchesWidth 4.00 InchesWeight 1.61 Pounds

MetricHeight 26.1 mmLength 147 mmWidth 101.6 mmWeight 0.73 kg

Environmental SpecificationsShock

Operating Shock (Read) 65G, 2 msNon-operating Shock 300G, 2 ms

AcousticsIdle Mode 25 dBA (average)Seek Mode 0 29 dBA (average)Seek Mode 3 26 dBA (average)

VibrationOperating

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

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

Electrical SpecificationsCurrent Requirements

Power DissipationRead/Write 6.00 WattsIdle 3.70 WattsStandby 0.80 WattsSleep 0.80 Watts

Page 17: CAOS - Portfolio 2010 - 2011

17University of Abertay

CE0714A

Page 18: CAOS - Portfolio 2010 - 2011

18University of Abertay

CE0714A

Power Supply UnitThe 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.

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

as a tradition drive. As these devices operate lasers, they are particular dangerous to take apart and

Figure 6: Compaq DVD-ROM

Page 19: CAOS - Portfolio 2010 - 2011

19University of Abertay

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

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 Canada1

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 (ANONYMOUS, 2010)

Page 20: CAOS - Portfolio 2010 - 2011

20University of Abertay

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

USRobotics 10/100 Mbps Network Card 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)

Page 21: CAOS - Portfolio 2010 - 2011

21University of Abertay

CE0714A

System ProfilingThe 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 ProfilingSystem Information revealed that the machine had:

2GB Total Memory 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 ProfilingSystem 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

Page 22: CAOS - Portfolio 2010 - 2011

22University of Abertay

CE0714A

The BIOS, Basic Input / Output System, contains a wealth of knowledge about the hardware of the

system being profiled.

Operating System ProfilingSystem 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

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.

Page 23: CAOS - Portfolio 2010 - 2011

23University of Abertay

CE0714A

Windows Vista 6.0.6000 Current Version changed to 6.0.6002 SP2

Windows 7 6.1.7600 RTM

(NIRMAL, 2009)

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 OS Manufacturer Microsoft Corporation 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 Page File C:\pagefile.sys

Page 24: CAOS - Portfolio 2010 - 2011

24University of Abertay

CE0714A

Page 25: CAOS - Portfolio 2010 - 2011

25University of Abertay

CE0714A

Data RepresentationA 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 (CONSORTIUM, Unicode, 2010). 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 numbers can be very space consuming, as well as very difficult to understand.

This 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.

BinaryBinary 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 1Table 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.

Page 26: CAOS - Portfolio 2010 - 2011

26University of Abertay

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.

HexadecimalHexadecimal 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

T

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

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.

The following questions are to be answered:

1) Convert the following from decimal to 8-bit binarya) 19 b) 96 c) 2502) Convert the following from binary to decimala) 0111 b) 1011010000113) What is the maximum integer that can be represented in 16 bit binary? Give your answer ina) Binary b) hex c) decimal4) What range of numbers can be represented by 16 bit two's complement?5) Convert the following binary numbers into hexadecimala) 101011101011 b) 11100110 c) 110010101111111010111010101111106) Perform the following binary additions:a) 00101 + 10110 b) 100111 + 100101 + 0000017) Perform the following operations using 8 bit two's complement arithmetic.a) 100 + 27 b) 84 + 52 c) 115 – 64 d) -85 - 448) Convert the following hexadecimal numbers to binary and decimala) 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 Bits3276 16384 8192 4096 2048 1024 512 256 128 64 32 16 8 4 2 1 DEC

Page 27: CAOS - Portfolio 2010 - 2011

27University of Abertay

CE0714A

80 0 0 1 0 0 1 1 190 1 1 0 0 0 0 0 961 1 1 1 1 0 1 0 250

0 1 1 1 71 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 = 19b) 0110 0000 = 96c) 1111 1010 = 250

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

Question 3:a) 1111 1111 1111 1111b) 0xFFFF

0xF is equal to 1111 (Binary) ∴ 1111 1111 1111 1111

F F F F ∴1111 1111 1111 1111 ≡ 0xFFFF

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 Value0000 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.

Page 28: CAOS - Portfolio 2010 - 2011

28University of Abertay

CE0714A

16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 Bits3276

816384 8192 4096 2048 1024 512 256 128 64 32 16 8 4 2 1 DEC

1 0 1 1 1 0 1 0 1 0 1 1 1 1 1 0Table 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 Bits

2147483648 1073741824 536870912 268435456 134217728 67108864 33554432 16777216 8388608 4194304 2097152 1048576 524288 262144 131072 65536

21474836

48

10737418

24

53687091

2

26843545

6

13421772

8

67108864

33554432

16777216

838860

8

419430

4

209715

2

104857

6

524288

262144

131072

65536

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

l

12 10 15 14 11 10 11 14

Hex C A F E B A B E

Table 7: Working out for Question 5-C

Question 6a) 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

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.

Page 29: CAOS - Portfolio 2010 - 2011

29University of Abertay

CE0714A

01001100 = Final Answer (Decimal 76)

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

a) 100 + 27100 = 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 0 1000 Carry 1 00 1000 Carry 1 000 1000 Carry 1 --------- 1000 1000 Final Answer =========

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

Page 30: CAOS - Portfolio 2010 - 2011

30University of Abertay

CE0714A

--------- 1011 0011 Final Answer =========

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

Table 8: Hexadecimal to Binary and Decimal Conversion

Binary ArithmeticHaving 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.

Page 31: CAOS - Portfolio 2010 - 2011

31University of Abertay

CE0714A

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.

Question 1) XOR OutputUltimately in binary, each gate has two inputs and one output, and as

Boolean algebra is based upon a logical sequence of events the output

is always the same under the same circumstances. That is there is no

alternative output possible. The XOR gate for instance can receive as

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 1 state – the output would be also at

logical 1, or True.

Question 2 & 3a) NAND OutputLogically we can make assumptions about the input of a gate from its

output. If the output of a NAND gate was FALSE, 0, we could deduce

that the inputs are not both set to the logical state of FALSE.

Alternatively, if the output was TRUE or 1, then both inputs must have

been set to the logical state of FALSE, or 0.

Table 10: XOR Truth Table

Table 11: NAND Truth Table

Input Output

X Y X ≠ Y

0 0 0

1 0 1

0 1 1

1 1 0

Input Output

X Y X ↑ Y

0 0 1

1 0 0

0 1 0

1 1 0

Page 32: CAOS - Portfolio 2010 - 2011

32University of Abertay

CE0714A

Question 3b) NOT OR GATE

Figure 9: OR gate being fed by two NOT Inputs

To generate the truth table we start at the Inputs, NOT them, and

put the new values into the OR gate to calculate the results.

Question 3c) XOR AND OUTPUT

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

A B XOR A AND B S C0 0 0 0 0 00 1 1 0 1 01 0 1 0 1 01 1 0 1 0 1

Table 13: : Circuit Truth Table

Question 4a) A AND NOT B GATE

Figure 11: A AND NOT B Gate

Table 12: Circuit Truth Table

A B NOT A NOT B Q0 0 1 1 10 1 1 0 11 0 0 1 11 1 0 0 0

Page 33: CAOS - Portfolio 2010 - 2011

33University of Abertay

CE0714A

A B AND A NOT B Q0 0 0 1 00 1 0 0 01 0 0 1 01 1 1 0 0

Table 14: AND A NOT B Gate Truth Table

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 R0 0 0 0 0 0 0 0 00 0 1 1 1 0 0 1 00 1 0 1 1 0 0 1 01 0 0 1 1 0 0 1 00 1 1 1 1 1 1 1 11 1 0 1 1 0 0 1 01 1 1 1 1 1 1 1 1Table 15: : A OR (B AND C)

Question 4c) (A AND B) NOR (A AND C) GATE

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

A B C OR A OR B AND A AND C Q R

Page 34: CAOS - Portfolio 2010 - 2011

34University of Abertay

CE0714A

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

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

Question 5) Logic Expression

A B C X0 0 0 00 0 1 00 1 0 10 1 1 11 0 0 11 0 1 11 1 0 01 1 1 0

Question 6) truth Table for Circuit in Question 5

Page 35: CAOS - Portfolio 2010 - 2011

35University of Abertay

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(); Question2(); 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

Page 36: CAOS - Portfolio 2010 - 2011

36University of Abertay

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 Console.WriteLine("NOT 0x18 Decimal : " + 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

Page 37: CAOS - Portfolio 2010 - 2011

37University of Abertay

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 { Console.WriteLine("B) 01010101 OR 10101010 = False"); }

// 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"); }

Page 38: CAOS - Portfolio 2010 - 2011

38University of Abertay

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 { 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");

Page 39: CAOS - Portfolio 2010 - 2011

39University of Abertay

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() { 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));

Page 40: CAOS - Portfolio 2010 - 2011

40University of Abertay

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(); }

/// <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() {

Page 41: CAOS - Portfolio 2010 - 2011

41University of Abertay

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

}}

Output:

Decimal : 255Decimal : 85Binary : 11111111Binary : 1010101Hexadecimal : FFHexadecimal : 55Decimal : 85Binary : 1010101Hexadecimal : 550xFF AND 0x55 : 1010101NOT 0x18 Decimal : -25NOT 0x18 Binary : 11111111111111111111111111100111NOT 0x18 Hexidecimal : FFFFFFE7Decimal (0x85 OR 01010101b) AND 15 : 005Binary (0x85 OR 01010101b) AND 15 : 101Hexidecimal (0x85 OR 01010101b) AND 15 : 05A) 01010101 AND 10101010 = FalseB) 01010101 OR 10101010 = TrueC) 01010101 XOR 10101010 = Trueb0 & 81 = Falseb4 & 81 = False

Page 42: CAOS - Portfolio 2010 - 2011

42University of Abertay

CE0714A

b6 & 81 = Falseb0 | 81 = Trueb4 | 81 = Trueb6 | 81 = Trueb0 ^ 81 = Trueb4 ^ 81 = Trueb6 ^ 81 = Truebyte A = 127byte A + 1 = 128sbyte A = 127sbyte A + 1 = -128A = 10 or in Binary 1010A = 40 or in Binary 101000A = 64 or in Binary 1000000A = 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

table, via a test rig.

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 Binary0 0 0 0 0000b0 1 1 0 0001b1 0 1 0 0001b1 1 1 1 0010b

Table 17: Half Adder Truth Table

Page 43: CAOS - Portfolio 2010 - 2011

43University of Abertay

CE0714A

Full AdderAs 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

Figure 17: Full Adder’s Test Rig

a b c q s Binary0 0 0 0 0 0000b0 0 1 1 0 0001b0 1 0 1 0 0001b0 1 1 0 1 0010b1 0 0 0 1 0010b1 0 1 1 1 0011b1 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.

Page 44: CAOS - Portfolio 2010 - 2011

44University of Abertay

CE0714A

Bit Adder Example

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

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.

Page 45: CAOS - Portfolio 2010 - 2011

45University of Abertay

CE0714A

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,

producing a Negative Edge flip-flop.

A Flip-Flop life cycle

Stage 1: RS Flip-Flop

Stage 2: Clocked RS Flip-Flop

Stage 3: D-Type Flip-Flop

Page 46: CAOS - Portfolio 2010 - 2011

46University of Abertay

CE0714A

4Bit Parallel Register

Figure 23: 4Bit Parallel Register

Figure 24: 4 Bit Shift Register

Page 47: CAOS - Portfolio 2010 - 2011

47University of Abertay

CE0714A

Figure 25: 4 Bit Up-Counter

Bits and PCsA 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.

Figure 26: 2-to-4 Line Decoder

Page 48: CAOS - Portfolio 2010 - 2011

48University of Abertay

CE0714A

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

Figure 28: 4-16 Line Decoder

Page 49: CAOS - Portfolio 2010 - 2011

49University of Abertay

CE0714A

Figure 29: 4-16 line Decoder Test Rig

Figure 30: 7 Segment LED Display Example

Page 50: CAOS - Portfolio 2010 - 2011

50University of Abertay

CE0714A

Figure 31: 0 LED Display

Figure 32: 1 LED Display

Figure 33: 2 LED Display

Figure 34: 3 LED Display

Page 51: CAOS - Portfolio 2010 - 2011

51University of Abertay

CE0714A

Figure 35: 4 LED Display

Figure 36: 5 LED Display

Figure 37: 6 LED Display

Figure 38: 7 LED Display

Page 52: CAOS - Portfolio 2010 - 2011

52University of Abertay

CE0714A

Figure 39: 8 LED Display

Figure 40: 9 LED Display

Figure 41: A LED Display

Figure 42: B LED Display

Page 53: CAOS - Portfolio 2010 - 2011

53University of Abertay

CE0714A

Figure 43: C LED Display

Figure 44: D LED Display

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 (III, Forrest M. Mims, 1987), I discovered a fully implemented controller with

Page 54: CAOS - Portfolio 2010 - 2011

54University of Abertay

CE0714A

all sub-components already designed. I have simply used these (AFTERAWER, 2010) to complete the

task.

Figure 47: 7 Segment LED Controller4

4 Completed Design by afterawe

Page 55: CAOS - Portfolio 2010 - 2011

55University of Abertay

CE0714A

Figure 48: BCD Controller

Figure 49: 7 Segment Display Controller

Page 56: CAOS - Portfolio 2010 - 2011

56University of Abertay

CE0714A

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.

Page 57: CAOS - Portfolio 2010 - 2011

57University of Abertay

CE0714A

Low-Level Programming

01first.asm - Arithmetic

Subtraction

Division

Divide by Zero

As was expected the software throws a “Divide by Zero” Exception.

Multiplication

; ===== WORK OUT 2 Minus 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.SUB AL,BL ; Subtract AL to BL. Answer goes into AL.END ; Program ends

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

; ===== WORK OUT 2 Divided by 2 ====================================CLO ; Close unwanted windows.MOV AL,2 ; Copy a 2 into the AL register.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 ===========================================

; ===== WORK OUT 2 Divided by 0 ====================================CLO ; Close unwanted windows.MOV CL,2 ; Copy a 2 into the CL register.MOV DL,0 ; Copy a 2 into the DL register.DIV AL,BL ; Divide CL by DL. Answer goes into CL.END ; Program ends

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

Page 58: CAOS - Portfolio 2010 - 2011

58University of Abertay

CE0714A

02tlight.asm - Traffic Lights

; ===== 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.END ; Program ends

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

; ===== 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.

MOV AL,C8 ; Copy 1100 1000 into the AL register.OUT 01 ; Send AL to Port One (The traffic lights).

; Turn on all the traffic lights.

MOV AL,30 ; Copy 0011 0000 into the AL register.OUT 01 ; Send AL to Port One (The traffic lights).

; Turn on all the traffic lights.

MOV AL,58 ; Copy 0101 1000 into the AL register.OUT 01 ; Send AL to Port One (The traffic lights).

; Turn on all the traffic lights.

JMP Start ; Jump back to the start.END ; Program ends.

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

YOUR TASK=========Use the help page on Hexadecimal and ASCII codes.Work out what hexadecimal numbers will activate thecorrect traffic lights. Modify the program to stepthe lights through a realistic sequence.

LEFT RIGHT BIN HEXRAGR AGxx

RED GREEN 1000 0100 84REDAMBER AMBER 1100 1000 C8GREEN RED 0011 0000 30AMBER REDAMBER 0101 1000 58

Page 59: CAOS - Portfolio 2010 - 2011

59University of Abertay

CE0714A

03move.asm - Data Moves

04IncJmp.asm - Counting

; ---------------------------------------------------------------

; A program to demonstrate MOV commands. Mov is short for move.

; ---------------------------------------------------------------CLO ; Close unwanted windows.

; ===== IMMEDIATE MOVES =====MOV AL,48 ; Copy "H" HEX into the AL registerMOV BL,45 ; Copy "E" HEX into the BL registerMOV CL,4C ; Copy "L" HEX into the CL registerMOV DL,4C ; Copy "L" HEX into the DL register

; ===== INDIRECT MOVES =====MOV [C0],AL ; Copy value in AL to RAM location [C0] C0 = HMOV [C1],BL ; Copy value in BL to RAM location [C1] C1 = EMOV [C2],CL ; Copy value in CL to RAM location [C2] C2 = LMOV [C3],DL ; Copy value in DL to RAM location [C3] C3 = LMOV AL,4F ; Copy "O" HEX into the AL registerMOV [C4],AL ; Copy value in AL to RAM location [C4] C4 = O

; ===== REGISTER INDIRECT MOVES =====MOV [CL],AL ; Copy the value in AL to the RAM

; location that CL points to.MOV BL,[CL] ; Copy the RAM location that CL points

; to into the BL register.

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.

; ====== Subtract 1 from the previous value in BLMOV BL,40 ; Set BL to 40

Rep1: ; Repeat this sectioDEC BL ; Subtract 1 from BLJMP Rep1 ; Repeat the loopEND ; End the program

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

; ====== ADD 3 to TotalMOV BL,1 ; Set BL to 1

Rep1: ; Repeat this sectioADD BL,3 ; Add 3 to BLJMP Rep1 ; Repeat the loopEND ; End the program

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

Page 60: CAOS - Portfolio 2010 - 2011

60University of Abertay

CE0714A

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

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.

; ===== MULTIPLYING BY TWOMOV BL,1 ; Set BL to 1

Rep1: ; Repeat this sectioMUL BL,2 ; Multiply BL by 2JMP Rep1 ; Repeat the loopEND ; End the program

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

; ===== Counting Fibonacci sequence of numbers =====================

MOV BL,0 ; Initial value stored in BL = 0MOV CL,1 ; Initial value stored in CL = 0MOV DL,0 ; The Result

Rep: ; Jump back to this label

ADD BL,CL ; ADD CL to BL (0 + 0) (0 + 1) (1 + 2) (2 + 3)PUSH BLPOP DL ; DL now equals the sum of BL + CLPUSH CLPOP BL ; BL Now Equals CLPUSH DLPOP CL ; CL now equals the Previous SUM of BL + CL

JMP Rep ; Jump back to Rep

END ; Program Ends

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

; --------------------------------------------------------------; 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; --------------------------------------------------------------

Page 61: CAOS - Portfolio 2010 - 2011

61University of Abertay

CE0714A

Harder! Store all the text you type in RAM when you type it in. When you press Enter, display the stored text on the VDU display.

; --------------------------------------------------------------; Input key presses from the keyboard until Enter is pressed.; --------------------------------------------------------------

CLO ; Close unwanted windows.MOV BL,C0 ; Copy C0 – Hex to BL

Rep:IN 00 ; Wait for key press - Store it in AL.CMP AL,0D ; Was it the Enter key? (ASCII 0D)MOV [BL], AL ; Copy the Contents of AL to the Video Location BLINC BL ; Move the Video Address on one placeJNZ Rep ; No - jump back. Yes - end.

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

Page 62: CAOS - Portfolio 2010 - 2011

62University of Abertay

CE0714A

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.

; --------------------------------------------------------------; 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 stackPUSH BL ; Save BL onto the stackPUSHF ; 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 StopMOV [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 markerMOV [BL],AL ; Copy NULL character to this position.

POPF ; Restore flags from the stackPOP BL ; Restore BL from the stackPOP AL ; Restore AL from the stack

RET ; Return from the procedure.; --------------------------------------------------------------; 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 CLMOV BL,70 ; Set BL to memory location 70

Again:MOV AL,[BL] ; Copy Memory contents to ALCMP AL,0 ; End of message (NULL Marker) FoundJZ Bottom ; If Found go to BottomMOV [CL],AL ; copy AL contents to Screen location CLINC CL ; Move the cursor on 1 place on VDUINC BL ; Goto the next memory locationJMP 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.

; --------------------------------------------------------------

Page 63: CAOS - Portfolio 2010 - 2011

63University of Abertay

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 StopPUSH AL ; Copy keypress to STACK LIFOINC DL ; Count how many characters were enteredJMP Rep ; Jump back to get the next character

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

CALL 40RET ; Return from the procedure.

; --------------------------------------------------------------; 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

Again:CMP DL,0 ; If We have done all the chars endJZ Bottom ; Go to end if donePOP BL ; Copy Memory contents to ALCMP BL,0 ; Is this the Null Character?JZ SKIPCMP BL,27 ; Is this the LF/CR (Return / Enter Key)?JZ SKIPMOV [CL],BL ; Copy the char in BL into the VDU locationINC CL ; Move the VDU location on one place

SKIP: ; Skip the displaying of a character!DEC DL ; Decrease the Character CounterJMP 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.

; --------------------------------------------------------------

Page 64: CAOS - Portfolio 2010 - 2011

64University of Abertay

CE0714A

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

Re-do the text input and display program with procedures. Use one procedure to input the text and one to display it.

; ---------------------------------------------------------------

; Traffic Lights with Time Delay

;

;------ The Main Program ----------------------------------------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.CALL 40 ; Wait a bit

MOV AL,C8 ; Copy 1100 1000 into the AL register.OUT 01 ; Send AL to Port One (The traffic lights).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 ; Wait a bit

MOV AL,58 ; Copy 0101 1000 into the AL register.OUT 01 ; Send BL to Port One (The traffic lights).CALL 40 ; Wait a bit

JMP Start ; Jump back to the start.HALT ; Program ends.

; ----- Time Delay Procedure Stored At Address [40] -------------ORG 40 ; Generate machine code from address [40]

PUSH BL ; Save AL on the stack.PUSHF ; Save the CPU flags on the stack.MOV BL,10 ; The Duration of the delay

Rep:DEC BL ; Subtract one from BL.JNZ REP ; Jump back to Rep if BL was not Zero.

POPF ; Restore the CPU flags from the stack.POP BL ; Restore BL from the stack.

RET ; Return from the procedure.; ---------------------------------------------------------------

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

Page 65: CAOS - Portfolio 2010 - 2011

65University of Abertay

CE0714A

; Get input from the keypboard; Display it on the console; Using Routines

;------ The Main Program ----------------------------------------CLO ; Close unwanted windows.

; --------------------------------------------------------------; Input key presses from the keyboard until Enter is pressed.; --------------------------------------------------------------

CLO ; Close unwanted windows.MOV BL,C0 ; Copy C0 - Hex to BLCALL 30 ; Call Get Input RoutineHALT ; End the program

; GET INPUT ---------------------------------------------------------ORG 30Rep:

IN 00 ; Wait for key press - Store it in AL.CMP AL,0D ; Was it the Enter key? (ASCII 0D)JZ ENDD ; Yes - end.CALL 40 ; Call Display Output RoutineJMP Rep ; Repeat the process

ENDD:RET ; Reurn from the routine

; DISPLAY OUTPUT ----------------------------------------------------ORG 40

MOV [BL], AL ; Copy the Contents of AL to the Video Location BLINC BL ; Move the Video Address on one placeRET ; return from the routine

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

Page 66: CAOS - Portfolio 2010 - 2011

66University of Abertay

CE0714A

07textio.asmTASK

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.

Page 67: CAOS - Portfolio 2010 - 2011

67University of Abertay

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 StopMOV [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 markerMOV [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 40MOV BL,A0 ; Go to beginning of the RAM

REP2:MOV AL,[BL] ; Get char from RAMCMP AL,0 ; Is it Null END OF LINE MARKER?JZ BOT ; Go To BOT We are done here!OR AL,20 ; OR MASK 0010 0000 (the difference between Upper and Lowercase)MOV [BL],AL ; Save the lowecase letter backINC BL ; Go to next RAM characterJMP 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 CLMOV BL,A0 ; Set BL to memory location A0

Again:MOV AL,[BL] ; Copy Memory contents to ALCMP AL,0 ; End of message (NULL Marker) FoundJZ Bottom ; If Found go to BottomMOV [CL],AL ; copy AL contents to Screen location CLINC CL ; Move the cursor on 1 place on VDUINC BL ; Goto the next memory locationJMP 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.

; --------------------------------------------------------------

Page 68: CAOS - Portfolio 2010 - 2011

68University of Abertay

CE0714A

18) Improve the traffic lights data table so there is an overlap with both sets of lights on red.

19) Use a data table to navigate the snake through the maze. This is on port 4. Send FF to the snake to reset it. Up, down left and right are controlled by the left four bits. The right four bits control the distance moved.

; ----- 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)

Start:MOV BL,02 ; 02 is start address of data table

Rep:MOV AL,[BL] ; Copy data from table to ALOUT 01 ; Output from AL register to port 01

CMP AL,98 ; Last item in data table ???JZ Start ; If yes then jump to StartINC BL ; In no then point BL to the next entryJMP Rep ; Jump back to do next table entry

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

Page 69: CAOS - Portfolio 2010 - 2011

69University of Abertay

CE0714A

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

JMP Start ; Skip past the data table.

DB FF ; Reset the snakeDB 4F ; Down MAX MovesDB 4F ; DB 4F ; DB 4F ; DB 4F ; DB 4F ; DB 4F ; DB 4F ;DB 4F ; DB 4F ; DB 47 ; DOWN HALF MAX DISTANCEDB 1F ; RIGHT MAX DISTANCEDB 1F ; RIGHT MAX DISTANCEDB 1F ; RIGHT MAX DISTANCEDB 8F ; UP MAX DISTANCEDB 8F ; UP MAX DISTANCEDB 8F ; UP MAX DISTANCEDB 8F ; UP MAX DISTANCEDB 1F ; RIGHT MAX DISTANCEDB 1F ; RIGHT MAX DISTANCEDB 1F ; RIGHT MAX DISTANCEDB 4F ; Down MAX DISTANCEDB 4F ; Down MAX DISTANCEDB 4F ; Down MAX DISTANCEDB 4F ; Down MAX DISTANCEDB 1F ; RIGHT MAX DISTANCEDB 1F ; RIGHT MAX DISTANCEDB 8F ; UP MAX DISTANCEDB 8F ; UP MAX DISTANCEDB 8F ; UP MAX DISTANCEDB 8F ; UP MAX DISTANCEDB 8F ; UP MAX DISTANCEDB 8F ; UP MAX DISTANCEDB 8F ; UP MAX DISTANCEDB 8F ; UP MAX DISTANCEDB 2F ; LEFT MAX DISTANCEDB 2F ; LEFT MAX DISTANCEDB 2F ; LEFT MAX DISTANCEDB 2F ; LEFT MAX DISTANCEDB 2F ; LEFT MAX DISTANCEDB 2F ; LEFT MAX DISTANCEDB 8F ; UP MAX DISTANCEDB 8F ; UP MAX DISTANCEDB 8F ; UP MAX DISTANCEDB 1F ; RIGHT MAX DISTANCEDB 1F ; RIGHT MAX DISTANCEDB 1F ; RIGHT MAX DISTANCEDB 1F ; RIGHT MAX DISTANCEDB 1F ; RIGHT MAX DISTANCEDB 1F ; RIGHT MAX DISTANCEDB 1F ; RIGHT MAX DISTANCEDB 1F ; RIGHT MAX DISTANCEDB 4F ; Down MAX MovesDB 4F ; DB 4F ; DB 4F ; DB 4F ; DB 4F ; DB 4F ; DB 4F ;DB 4F ;DB 4F ; DB 4F ; DB 4A ; STOP A LITTLE SHORT OF MAX DISTANCE

DB 58 ; Last entry is also used as end marker

Start:MOV BL,02 ; 02 is start address of data table

Rep:MOV AL,[BL] ; Copy data from table to ALOUT 04 ; Output from AL register to port 01

CMP AL,58 ; Last item in data table ???JZ Start ; If yes then jump to StartINC BL ; In no then point BL to the next entryJMP Rep ; Jump back to do next table entry

END

Page 70: CAOS - Portfolio 2010 - 2011

70University of Abertay

CE0714A

20) Write a program to spin the stepper motor. Activate bits 1, 2, 4 and 8 in sequence to energise the electromagnets in turn. The motor can be half stepped by turning on pairs of magnets followed by a single magnet followed by a pair and so on.

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.

DB 1 ; Activate Elctro Magnet 1DB 2 ; Activate Elctro Magnet 2DB 4 ; Activate Elctro Magnet 4 (next is 8)DB 8 ; Last entry is also used as end marker

Start:MOV BL,02 ; 02 is start address of data table

Rep:MOV AL,[BL] ; Copy data from table to ALOUT 05 ; Output from AL register to port 01

CMP AL,8 ; Last item in data table ???JZ Start ; If yes then jump to StartINC BL ; In no then point BL to the next entryJMP Rep ; Jump back to do next table entry

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

Page 71: CAOS - Portfolio 2010 - 2011

71University of Abertay

CE0714A

09param.asm22) Write a procedure that doubles a number. Pass the single parameter into the procedure using a register. Use the same register to return the result.

23) Write a procedure to invert all the bits in a byte. All the zeros should become ones. All the ones should become zeros. Pass the value to

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

JMP Start ; Skip past the data table.

DB 1 ; Activate Elctro Magnet 1DB 2 ; Activate Elctro Magnet 2DB 4 ; Activate Elctro Magnet 4

DB 4 ; Activate Elctro Magnet 4DB 2 ; Activate Elctro Magnet 2 DB 1 ; Activate Elctro Magnet 1

DB 2 ; Activate Elctro Magnet 2DB 4 ; Activate Elctro Magnet 4 (next is 8)DB 8 ; Last entry is also used as end marker

Start:MOV BL,02 ; 02 is start address of data table

Rep:MOV AL,[BL] ; Copy data from table to ALOUT 05 ; Output from AL register to port 01

CMP AL,8 ; Last item in data table ???JZ Start ; If yes then jump to StartINC BL ; In no then point BL to the next entryJMP Rep ; Jump back to do next table entry

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

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

; ----- Use Registers to pass parameters into a procedure ------

JMP Start ; Skip over bytes used for data storage

Start:MOV AL,5CALL 30 ; A procedure to Double AL Value

; Result returned in AL.

; ----- A procedure to Double a Number held in AL -------------------------

; Parameters passed into procedure using AL and BL; Result returned in AL; This method is simple but is no good if there are a ; lot of parameters to be passed.

ORG 30 ; Code starts at address [30]

MUL AL,2 ; Do the Multiplication. Result goes into AL

RET ; Return from the procedure

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

Page 72: CAOS - Portfolio 2010 - 2011

72University of Abertay

CE0714A

be processed into the procedure using a RAM location. Return the result in the same RAM location.

24) Write a procedure that works out Factorial N. This example shows one method for working out factorial N. Factorial 5 is 5 * 4 * 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 -------------------; Start Value 10100101b = 0xA5; Result 1011010b = 0x5A; ----- Use Registers to pass parameters into a procedure ------

JMP Start ; Skip over bytes used for data storageDB 0 ; Reserve a byte of RAM at address [02]

Start:MOV AL,A5 ; AL = 10100101bMOV [02],AL ; Store 10100101b into address [02]CALL 40

; ----- A procedure to Double a Number held in AL -------------------------

; Parameters passed into procedure using AL and BL; Result returned in AL; 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

MOV [02],AL ;Store result in 02

RET ; Return from the procedure

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

Page 73: CAOS - Portfolio 2010 - 2011

73University of Abertay

CE0714A

25) Write a procedure that works out Factorial N. Use the stack for parameter passing. Write a recursive 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.

; ----- EXAMPLE 9 ------- Passing Parameters -------------------; Calculate the Factorial of 5; ----- Use Registers to pass parameters into a procedure ------

JMP Start ; Skip over bytes used for data storage

Start:MOV AL,5 ; AL = 5PUSH AL ; Throw it on the stackCALL 40 ; Call the routine to calculate the factorial

; ----- A procedure to Double a Number held in AL -------------------------

ORG 40 ; Code starts at address [40]POP BL ; IGNORE THE STACK FOR CALL 40POP BL ; BL now = 5PUSH BL ; CL Will be the counterPOP CLDEC CL ; First Multiplication is one less than starting number

REP:CMP CL,0 ;JZ ENDD ; If counted to zero leaveMUL BL,CL ; Multiply CL by the counterDEC CL ; Reduce the counter by 1JMP REP

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

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

; ---- ALTERNATIVELY RECURSION COULD HAVE BEEN USED.

Page 74: CAOS - Portfolio 2010 - 2011

74University of Abertay

CE0714A

10swint.asm

26) Write a new interrupt 02 that fetches a key press from the keyboard and stores it into RAM. The IBM PC allocates 16 bytes for key press storage. The 16 locations are used in a circular fashion.

; RECURSIVE FACTORIAL CALCULATOR

Start: MOV AL,5 ; AL = 5, the number to factorise.PUSH AL ; Throw it on the stackCALL 40 ; Call the ROUTINE at Address 40HALT ; STOP THE PROGRAM

;-------------------------------; THE RECURSIVE FACTORIAL ROUTINE

ORG 40 ; THE FACTORISING ROUTINE (RECURSIVE)POP BL ; IGNORE THE STACK FOR THE CALL 40POP BL ; GET THE COUNTER and put it in BLDEC BL ; One too many so reduce the counter by oneCMP BL,1 ; Stop if Counter = 1JZ BOTMUL AL,BL ; Multiply CL by the CounterPUSH BL ; Throw the counter on the stackCALL 40 ; CALL SELF (Recursion)

BOT:RET

END

Page 75: CAOS - Portfolio 2010 - 2011

75University of Abertay

CE0714A

27) Create a new interrupt that puts characters onto the next free screen location. See if you can get correct behaviour in response to the Enter key being pressed (fairly easy) and if the Back Space key is pressed (harder).

A Comparison of Low and High Level Languages

; --------------------------------------------------------------; An example of software interrupts.; --------------------------------------------------------------

JMP Start ; Jump past table of interrupt vectorsDB 51 ; Vector at 02 pointing to address 51

Start:

INT 02 ; Do interrupt 02JMP Start

; --------------------------------------------------------------

ORG 50DB E0 ; Data byte - could be a whole table here

; Interrupt code starts hereMOV CL,40 ; [40] is the address where the text willPUSH AL ; Save AL onto the stackPUSH CL ; Save CL onto the stackPUSHF ; 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 StopMOV [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 markerMOV [CL],AL ; Copy NULL character to this position.

POPF ; Restore flags from the stackPOP CL ; Restore CL from the stackPOP AL ; Restore AL from the stack

IRET; --------------------------------------------------------------; --------------------------------------------------------------

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

Page 76: CAOS - Portfolio 2010 - 2011

76University of Abertay

CE0714A

Error Detection

Page 77: CAOS - Portfolio 2010 - 2011

77University of Abertay

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/>

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/>

Page 78: CAOS - Portfolio 2010 - 2011

78University of Abertay

CE0714A