Hexadecimal Notation - PowerPoint PPT Presentation

About This Presentation
Title:

Hexadecimal Notation

Description:

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: 160 = 1, 161 ... Notations conform to C language syntax ... – PowerPoint PPT presentation

Number of Views:49
Avg rating:3.0/5.0
Slides: 21
Provided by: professora5
Learn more at: https://www.cs.usfca.edu
Category:

less

Transcript and Presenter's Notes

Title: Hexadecimal Notation


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

2
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 160 1,
    161 16, 162 256, 163 4096,
  • Write 32-bit addresses using 8 hex digits
  • Example This 32-bit binary number
  • 11000000000000000000000000000000 is written
    more briefly as C0000000 (hex)

3
nybbles
  • Each hex digit represents 4-bits

0 0000 8 1000 1 0001 9 1001 2 0010 A
1010 3 0011 B 1011 4 0100 C 1100 5
0101 D 1101 6 0110 E 1110 7 0111 F
1111
4
Conversions
  • Register AL holds 8 binary digits (bits)
  • Example AL 01100001 (binary)
  • One byte (8-bits) equals two nybbles AL
    0110 0001
  • Each nybble (4-bits) is just one hex digit
  • Example AL 61 (hex)

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

6
ASCII-codes in hex
  • Uppercase letter A is ascii-code 65
  • Very often its 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 01000001 and 0x61
    represents 01100001
  • This suggest a way to do ascii conversions

7
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 01100001, , 01111010
  • uppercase 01000001, , 01011010
  • We see bit number 5 is where they differ!

8
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

9
The toupper.s program
  • We can write an assembly language loop to convert
    a users 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 operands size

10
The programs loop
  • movl buffer, ebx
  • movl nbytes, ecx
  • again cmpb a, (ebx)
  • jb nochg
  • cmpb z, (ebx)
  • ja nochg
  • andb 0xDF, (ebx)
  • nochg incl ebx
  • loop again

11
The password program
main
obtain_password
notify_the_user
grant_or_refuse
verify_validity
request_input
receive_reply
12
Enhanced password
main
obtain_password
notify_the_user
grant_or_refuse
verify_validity
request_input
receive_reply
use_uppercase
13
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

14
Flowcharts
enter
enter
initializations
initializations
condition
action
FALSE
TRUE
condition
TRUE
action
FALSE
leave
leave
UNTIL-LOOP
WHILE-LOOP
15
A typical WHILE loop
  • movb FALSE, done
  • again
  • cmpb FALSE, done
  • jne finis
  • the body of the loop goes here
  • (and may alter the done flag)
  • jmp again
  • finis

16
A typical UNTIL loop
  • movb TRUE, done
  • again
  • the body of the loop goes here
  • (and may alter the done flag)
  • cmpb TRUE, done
  • je again

17
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 loops 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 and jecxz
  • Also (for early exits) loope/loopz
    and loopne/loopnz

18
A typical counted loop
  • movl array, ebx
  • movl 0, eax
  • movl 50, ecx
  • nxadd addl (ebx), eax
  • addl 4, ebx
  • loop nxadd
  • movl eax, total

19
Might your count be zero?
  • movl nbytes, ecx
  • jecxz finis
  • again
  • the body of your loop goes here
  • loop again
  • finis

20
An early exit example
  • gets the first non-blank character from
    inbuf
  • (where nbytes is length of the inbuf
    array)
  • movl inbuf, esi
  • movl nbytes, ecx
  • again movb (esi), al
  • incl esi
  • cmpb , al
  • loope again
Write a Comment
User Comments (0)
About PowerShow.com