Post on 14-Apr-2017
Embed Size (px)
Assembly Language - Lab (1)
Agenda Logistics CourseSites Introduction Data Representation
Year Work (25 Marks)Assignments Lab workProject4
AssignmentsAssignments are INDIVIDUAL work. Never share code/solution.
Honor CodeMy answers will be my own work.I will not make solutions available or seen by anyone else.
Violations:Plagiarism (copy all or part of it)Representing the work of another as ones own work
Honor Code Violation PenaltiesThree Strike Policy1st incident 25% of current assignment/lab work2nd incident 50% of current assignment/lab work3rd incident+ 100% of current assignment/lab work
This will be applied to both sides8
Why Assembly?All high-level languages are an abstraction how the computer works, abstraction means the programmer dont have to worry about the computer details.
Assembly is a really good way to understand what is the computer doing because you control exactly what happens at each step.
Why Assembly?Assembly language gives the programmer the ability to perform technical tasks that would be difficult in highlevel languages including total control on the machine.
Software written in assembly language runs faster than the same one written in highlevel language and takes less amount of memory if the programmer welloptimized the assembly program code.
The machine code program produced using the assembler takes up less memory space than the compiled version of the program.11
Why Assembly?Learning assembly language gives deep understanding of the computers organization and architecture and how programs run, since it is necessary to know the architecture of the processor or controller in order to write assembly code.
What can we do using Assembly?Device Driver: is a program that controls a particular type of device that is attached to your computer.Only assembly and C can implement this since they give you a full control over the hardware.
What can we do using Assembly?Virus Programming: a simple program that infects other programs:1. by injecting itself in the end of the program2. by applying changes to file header and RPT (Relocation pointer table) to execute the virus first and execute the host program
What can we do using Assembly?Reverse Engineering: is the process of reversing code from a machine language (binary code) using disassembler, then we can:analyze and understand the programchanging features in program (ex: cracking the program)debugging programwithout having the source code of the program15
What can we do using Assembly?Embedded Software: a software written to control a machine or device, that is specialized for a certain device, and has time and memory constraints, such as telephone, automobile, air-condition control system, video cards, sound cards, printers, etc.Since assembly is the fastest language and takes the lowest memory, it is the best for embedded system.
Machine Language VS Assembly Language
Machine LanguageComputers work only with 0s and 1s.
Every program instruction or data element must be in binary to be manipulated by computer machine.
Therefore, any program understood by machine has to be written in machine language, however machine language is too hard to write and maintain.
Machine LanguageMachine Language is a set of binary codes (0s and 1s) that represent instructions of a specific machine. It is machinedependent.
For example, the instruction8B D8 means copy content from AX register to BX register.
Assembly LanguageAssembly language is developed to make programming easier than programming using machine language.
Assembly language is a set of mnemonics (symbols) for machine code instructions plus other features that make programming easier.
Assembly LanguageTo run program written in assembly language, we should have a converter (or translator) which converts these labels and mnemonics to their corresponding machine codes in 0s and 1s. This converter is called assembler.
Assembly LanguageAssembly Language is a low-level (machinelevel) programming language that uses mnemonics instead of numeric codes to simplify programming.
For example, the instructionmov BX, AX means copy content from AX register to BX register.
Each statement in assembly code has a one-to-one relationship with machine language instructions, in other words each statement corresponds to a singlemachine codeinstruction.
Each assembly language is machinedependent which means it is specific to a particularcomputer architecture.
In contrast to most high-level programming languages, which are generally portable across multiple systems.
Assembly LanguageWell use Irvine Library with Visual Studio to write our Assembly code.
Data Representation Numbering Systems Conversions25
Numbering SystemsData Representation
26SystemBasePossible DigitsBinary20 and 1Octal80, 1, 2, 3, 4, 5, 6, and 7Decimal100, 1, 2, 3, 4, 5, 6, 7, 8, and 9Hexadecimal160, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F
Converting from unsigned binary to decimal
11011021x25 + 1x24 + 0x23 + 1x22 + 1x21 + 0x20=1x32 + 1x16 + 0 + 1x4 + 1x2 + 0=32 + 16 + 4 + 2=5410
Converting from unsigned binary to decimal
111100002 1x27 + 1x26 + 1x25 + 1x24 + 0x23 + 0x22 + 0x21 + 0x20=1x128 + 1x64 + 1x32 + 1x16 + 0 + 0 + 0 + 0=128 + 64 + 32 + 16=24010
Converting from signed binary to decimal
0010101020x26 + 1x25 + 0x24 + 1x23 + 0x22 + 1x21 + 0x20=0 + 1x32 + 0 + 1x8 + 0 + 1x2 + 0=32 + 8 + 2=+4210
291st bit is 0, then the number is positive
Converting from signed binary to decimal
Get the 2s complement2s complement = 1s complement + 100010000 = 00001111 + 1
Convert the 2s complement to decimal and attach the negative sign 0x27 + 0x26 + 0x25 + 1x24 + 0x23 + 0x22 + 0x21 + 0x20=0 + 0 + 0 + 16 + 0 + 0 + 0 + 0=16=-1610301st bit is 1, then the number is negative
=101112DivisionQuotientRemainder23 / 2 = 11.511111 / 2 = 5.5515 / 2 = 2.5212 / 2 = 1101 / 2 = 0.50110111
Stop when quotient = 031Converting from unsigned decimal to binary
-2310Convert the decimal value into binary
DivisionQuotientRemainder23 / 2 = 11.511111 / 2 = 5.5515 / 2 = 2.5212 / 2 = 1101 / 2 = 0.50110111
Stop when quotient = 032Converting from signed decimal to binary
If the original number is negative, then get the 2s complement of the resultResult = 101112 = 000101112
2s complement = 1s complement + 1 = 11101000 + 1 = 11101001233Converting from signed decimal to binary
Converting from unsigned binary to hexadecimalEach hexadecimal digit corresponds to 4 binary bits.0101 10112Convert each 4 bits to a hexadecimal digit
340 x 23 + 1 x 22 + 0 x 21 + 1 x 201 x 23 + 0 x 22 + 1 x 21 + 1 x 200 + 1 x 4 + 0 + 1 x 11 x 8 + 0 + 1 x 2 + 1 x 14 + 18 + 2 + 15115B
A616Convert each hexadecimal digit to 4 bits
=101001102A = 10DivisionQuotientRemainder10 / 2 = 5505 / 2 = 2.5212 / 2 = 1101 / 2 = 0.5011010
6DivisionQuotientRemainder6 / 2 = 3303 / 2 = 1.5111 / 2 = 0.50100110
35Converting from unsigned hexadecimal to binary
Addition and Subtraction1s ComplementCovert each 1 to 0, and each 0 to 1.1s complement of 10110102 = 010010122s ComplementAdd 1 to the 1s complement.2s complement of 10110102 = 010011022s complement is used in representing negative numbers.36Numbering Systems
Binary Operations11001 + 10101 = 101110The operations result does not fit in 5 bits, so the underlined 1 in the previous number is called a carry.
11001 10101 = 11001 + 01011 = 00100with carry = 1Carry = 1 in subtraction means that the result is positive with no borrow.
10101 11001 = 10101 + 00111 = 11100with carry = 0Carry = 0 in subtraction means that the result is negative with borrow.372s complement of 101012s complement of 11001Numbering Systems
Hexadecimal Operations23D9 + 94BE9 + 14 = 2323 16 = 7with carry13 + 11 + 1 = 2525 16 = 9with carry3 + 4 + 1 = 82 + 9 = B= B897
59F 2B815 8 = 7(9 + 16) 11 = 14 (E)4 2 = 2= 2E738Numbering Systems
Additional Examples000101101010011110010100)2 = )161234)16 = )10422)10 = )163628286A + 4245584B )16 = )16C675 A247)16 = )16
16A7941(16^3)+2(16^2)+3(16)+4 = 46601A6786D80B5242E
All data stored in memory is numeric.
Characters are stored by using a character code that maps numbers to characters.
One of the most common character codes is known as ASCII (American Standard Code for Information Interchange). It uses 1 byte (8 bits) to encode characters. Therefore, it is limited to encode only 256 (28) characters.
A new and more complete code that is supplanting ASCII is Unicode. It uses 2 bytes (16 bits) to encode characters. Therefore, it is capable to encode 65536 (216) characters.ASCII Code40