Hexadecimal Notation Using sixteen as a number base when representing binary data.

Slides:



Advertisements
Similar presentations
COMP3221: Microprocessors and Embedded Systems--Lecture 1 1 COMP3221: Microprocessors and Embedded Systems Lecture 3: Number Systems (I)
Advertisements

Integer Types. Bits and bytes A bit is a single two-valued quantity: yes or no, true or false, on or off, high or low, good or bad One bit can distinguish.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
28-Jun-15 Number Systems. 2 Bits and bytes A bit is a single two-valued quantity: yes or no, true or false, on or off, high or low, good or bad One bit.
Primitive Types Java supports two kinds of types of values – objects, and – values of primitive data types variables store – either references to objects.
Bit Operations C is well suited to system programming because it contains operators that can manipulate data at the bit level –Example: The Internet requires.
A bit can have one of two values: 0 or 1. The C language provides four operators that can be used to perform bitwise operations on the individual bits.
1 Homework Reading –PAL, pp Machine Projects –MP2 due at start of Class 12 Labs –Continue labs with your assigned section.
Homework Reading –Finish K&R Chapter 1 (if not done yet) –Start K&R Chapter 2 for next time. Programming Assignments –DON’T USE and string library functions,
Real Numbers and the Decimal Number System
Binary and Hexadecimal Numbers
Homework Reading Programming Assignments
1 Lab Session-III CSIT-120 Fall 2000 Revising Previous session Data input and output While loop Exercise Limits and Bounds Session III-B (starts on slide.
How Computers Work Dr. John P. Abraham Professor UTPA.
DECIMAL BASE Based on power of 10 In the number 2,468 – from right to left -- the 8 represents the ones, the 6 represents the tens, the 4 represents the.
1 What is a loop? A loop is a repetition control structure that causes a single statement or block to be executed repeatedly Loops.
Chapter 3 Elements of Assembly Language. 3.1 Assembly Language Statements.
EX_01.1/46 Numeric Systems. EX_01.2/46 Overview Numeric systems – general, Binary numbers, Octal numbers, Hexadecimal system, Data units, ASCII code,
1 Programming in Machine Language SCSC 311 Spring 2011.
Eng.Samra Essalaimeh Philadelphia University 2013/ nd Semester PIC Microcontrollers.
STRINGS CMSC 201 – Lab 3. Overview Objectives for today's lab:  Obtain experience using strings in Python, including looping over characters in strings.
The Hexadecimal Number System and Memory Addressing ISAT 121.
Positional Notation 642 in base 10 positional notation is:
Microprocessors Monday, Apr. 13 Dr. Asmaa Farouk Faculty of Engineering, Electrical Department, Assiut University.
EEL 3801C EEL 3801 Part I Computing Basics. EEL 3801C Data Representation Digital computers are binary in nature. They operate only on 0’s and 1’s. Everything.
Hexadecimal Data Representation. Objectives  Know how the Hexadecimal counting system works  Be able to convert between denary, binary & hexadecimal.
THE BINARY NUMBER SYSTEM “There are only 10 types of people in this world: Those who understand BINARY and those who do not.”
Repetition and Iteration ANSI-C. Repetition We need a control instruction to allows us to execute an statement or a set of statements as many times as.
1 Computer Science LESSON 1 on Number Bases. 2 Objective In this lesson you’ll learn about different Number Bases, specifically about those used by the.
Springfield Technical Community College Center for Business and Technology.
1 Logic, Shift, and Rotate Instructions Read Sections 6.2, 7.2 and 7.3 of textbook.
Chapter 10 Instruction Sets: Characteristics and Functions Felipe Navarro Luis Gomez Collin Brown.
Implementing ‘noecho’ Programming details regarding the Linux implementation for ‘struct termios’ objects.
Topic 14.1 Extended Hexadecimal  Decimal is base 10 and uses 10 digits (0,1,2,3,4,5,6,7,8,9).  Binary is base 2 and uses 2 digits (0,1).  Computers.
COMP1070/2002/lec1/H.Melikian COMP1070 Lecture #2 Computers and Computer Languages Some terminology What is Software? Operating Systems.
C Language 1 Program Looping. C Language2 Topics Program looping Program looping Relational operators / expressions Relational operators / expressions.
CSC 3210 Computer Organization and Programming
Introduction to Computing Systems and Programming Programming.
Programming in Java (COP 2250) Lecture 12 & 13 Chengyong Yang Fall, 2005.
The Hexadecimal System is base 16. It is a shorthand method for representing the 8-bit bytes that are stored in the computer system. This system was chosen.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Base 16 (hexadecimal) Uses the decimal digits and the first letters of the alphabet to encode 4 binary bits (16=2 4 ) abcdef or ABCDEF.
NUMBER SYSTEMS.
Unit 18: Computational Thinking
Programming in Machine Language
Digital Electronics INTRODUCTION ANALOG VS DIGITAL NUMBER SYSTEMS.
Homework Reading Labs PAL, pp
Computer Science LESSON 1 on Number Bases.
Aaron Miller David Cohen Spring 2011
Number System conversions
Binary Quiz UIN: ____________________
Number Systems and Binary Arithmetic
Loops The loop blocks you've used in Scratch can all be recreated in C! Loops allow for the repetition of code until a condition is met. There are three.
Microprocessor and Assembly Language
Binary Lesson 3 Hexadecimal
Binary Lesson 8a IPv6 Addresses: Hexadecimal
Homework Reading Machine Projects Labs PAL, pp
Binary Lesson 3 Hexadecimal
Binary Lesson 3 Hexadecimal
Binary Lesson 8 IPv6 Addresses: Hexadecimal
Binary Lesson 3 Hexadecimal
AP Computer Science LESSON 1 on Number Bases.
John Owen, Rockport Fulton HS
Binary Lesson 4 Hexadecimal and Binary Practice
Homework Reading Programming Assignments Finish K&R Chapter 1
Numeral systems (radix)
Binary Lesson 4 Hexadecimal and Binary Practice
Jump & Loop instructions
Binary Lesson 7 Review of Binary and Hexadecimal
Computer Architecture and System Programming Laboratory
Presentation transcript:

Hexadecimal Notation Using sixteen as a number base when representing binary data

Positional Notation (Base 16) Set of sixteen digit-symbols: 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F Position-values are powers of sixteen: 16 0 = 1, 16 1 = 16, 16 2 = 256, 16 3 = 4096, … Write 32-bit addresses using 8 hex digits Example: This 32-bit binary number is written more briefly as: C (hex)

‘nybbles’ Each hex digit represents 4-bits: 0 = = = = = 0010A = = 0011B = = 0100C = = 0101D = = 0110E = = 0111F = 1111

Conversions Register AL holds 8 binary digits (bits) Example:AL = (binary) One byte (8-bits) equals two nybbles: AL = Each nybble (4-bits) is just one hex digit: Example:AL = 61 (hex)

Interpreting numbers Our assembler understands hex notation Assembler also recognizes ‘octal’ (base 8) Notations conform to C language syntax Numbers are assumed decimal (base 10) unless otherwise indicated (via a ‘prefix’) Example:50 means ‘fifty’ (base 10) but 0x50 means ‘eighty’ (base 16) and 050 means ‘forty’ (base 8)

ASCII-codes in hex Uppercase letter ‘A’ is ascii-code 65 Very often it’s written (in hex) as 0x41 Lowercase letter ‘a’ is ascii-code 97 And very often is written (in hex) as 0x61 Hex makes it easy to ‘see’ the binary data Examples: 0x41 represents and0x61 represents This suggest a way to do ascii conversions

Lowercase vs. Uppercase Ascii-codes for lowercase letters (‘a’-’z’): 0x61, 0x62, 0x63, …, 0x79, 0x7A Ascii-codes for uppercase letters (‘A’-’Z’): 0x41, 0x42, 0x43, …, 0x59, 0x5A We can visualize these values as ‘bits’ – lowercase: , …, – uppercase: , …, We see bit number 5 is where they differ!

Using ‘AND’ and ‘OR’ We can use the ‘bitwise-OR’ operator to convert uppercase to lowercase: i.e., lowercase = uppercase | 0x20; We can use the ‘bitwise-AND’ operator to convert lowercase to uppercase: i.e.,uppercase = lowercase & 0xDF;

The ‘toupper.s’ program We can write an assembly language loop to convert a user’s input into uppercase Select a 32-bit register to use as a ‘pointer’ Example: movl$buffer, %ebx In case EBX points to a lowercase letter, we can convert it to uppercase by using: andb$0xDF, (%ebx) # resets bit 5 to 0 The ‘b’ suffix here tells the operand’s size

The program’s loop movl$buffer, %ebx movlnbytes, %ecx again:cmpb$’a’, (%ebx) jbnochg cmpb$’z’, (%ebx) janochg andb$0xDF, (%ebx) nochg:incl%ebx loopagain

The ‘password’ program main obtain_passwordnotify_the_usergrant_or_refuseverify_validity request_inputreceive_reply

Enhanced ‘password’ main obtain_passwordnotify_the_usergrant_or_refuseverify_validity request_inputreceive_reply use_uppercase

Typical kinds of loops ‘while’ loops: So long as a condition is true perform the action in the body of this loop ‘until’ loops: Perform the action in the body of this loop until condition is no longer true Note: a while-loop can be empty, but an until-loop always executes at least once

Flowcharts condition action TRUE leave FALSE TRUE FALSE leave WHILE-LOOP UNTIL-LOOP initializations enter

A typical ‘WHILE’ loop movb$FALSE, done again: cmpb$FALSE, done jnefinis # the body of the loop goes here # (and may alter the ‘done’ flag) jmpagain finis:

A typical ‘UNTIL’ loop movb$TRUE, done again: # the body of the loop goes here # (and may alter the ‘done’ flag) cmpb$TRUE, done jeagain

‘Counted’ loops Very often we know in advance the number of times that the body of a loop needs to execute In these cases the loop’s exit-condition is based on the changing value of a counter Sometimes a counted loop needs to allow for an early exit (before the final count is reached) Pentium has some special support-instructions: loop andjecxz Also (for early exits): loope/loopz and loopne/loopnz

A typical ‘counted’ loop movl$array, %ebx movl$0, %eax movl$50, %ecx nxadd:addl(%ebx), %eax addl$4, %ebx loopnxadd movl%eax, total

Might your count be zero? movlnbytes, %ecx jecxzfinis again: # the body of your loop goes here loopagain finis:

An ‘early exit’ example # gets the first non-blank character from ‘inbuf’ # (where ‘nbytes’ is length of the ‘inbuf’ array) movl$inbuf, %esi movlnbytes, %ecx again:movb(%esi), %al incl%esi cmpb$’ ’, %al loopeagain