A Hexadecimal Calculator

Slides:



Advertisements
Similar presentations
Defining and processing tables
Advertisements

Program.-(9)* Write a program Input two numbers from keyboard and multiply of given values using by variables. Input value No 1 input value No2 Multiply.
BINARY & HEX I/O. Binary input : read in a binary number from keyboard, followed by a carriage return. character strings of 1’s & 0’ we need to convert.
DOS and BIOS Interrupts DOS and BIOS interrupts are used to perform some very useful functions, such as displaying data to the monitor, reading data from.
ICS312 Set 2 Representation of Numbers and Characters.
Writing and reading files. Creating a file on a disk Get a file handle from system Use INT 21H function 3C to create a directory entry for the file Use.
ACOE2511 Assembly Language Arithmetic and Logic Instructions.
Computer Organization & Assembly Language
Assembly Language for Intel-Based Computers Chapter 15: BIOS-Level Programming (c) Pearson Education, All rights reserved. You may modify and.
Assembly Language for Intel-Based Computers Chapter 5: Procedures Kip R. Irvine.
Flow Control Instructions
9-1 ECE 424 Design of Microprocessor-Based Systems Haibo Wang ECE Department Southern Illinois University Carbondale, IL x86 Instructions Part.
Kip Irvine: Assembly Language for Intel-Based Computers
8.4 Instruction Execution Times TOBIN PROC FAR SUB AX,AX MOV DX,AX MOV CX,4 NEXTD: PUSH CX SUB BP,BP MOV CX,4 GETNUM: RCL BX,1 RCL BP,1 LOOP GETNUM.
BR 6/001 Ways to Handle I/O (Input/Ouput) For Output –Use Irvine16 Functions Writechar, WriteBin, WriteInt, Writehex, Writestring –Use DOS (Int 21h) Functions.
ICS312 Set 4 Program Structure. Outline for a SMALL Model Program Note the quiz at the next lecture will be to reproduce this slide.MODEL SMALL.586 ;
Lab 5 Part C Write to the screen a character string that uses a ‘$’ to indicate the end of the string. Do not write the ‘$’ to the screen. Use DOS Interrupt.
Lecture 11 Last notes on interrupts and exam review Dr. Dimitrios S. Nikolopoulos CSL/UIUC.
ECE291 Computer Engineering II Lecture 13 Dr. Zbigniew Kalbarczyk University of Illinois at Urbana- Champaign.
Flag Control instructions CLC clear carry flag CF = 0 STC set carry flag CF= 1 CMC complement carry flag [CF] CF.
11.1/36 Repeat: From Bits and Pieces Till Strings.
BIOS and DOS Programming in DOS INT 10 and 21H. Interrupts There are some extremely useful subroutines within BIOS or DOS that are available to the user.
ICS312 Set 1 Representation of Numbers and Characters.
ICS312 Set 9 Logic & Shift Instructions. Logic & Shift Instructions Logic and Shift Instructions can be used to change the bit values in an operand. The.
Microprocessors Monday, Apr. 13 Dr. Asmaa Farouk Faculty of Engineering, Electrical Department, Assiut University.
Boolean and Comparison Instructions Operation Description ANDAND Destination, Source OROR Destination, Source XORXOR Destination, Source NOTNOT Destination.
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#5) By Dr. Syed Noman.
Arithmetic Flags and Instructions
Executing and Linking an assembly program. Lesson plan Review Program logic and control Practice exercise Assembling, Linking and Executing Programs Practice.
Logic Conditional Processing. Status flags - review The Zero flag is set when the result of an operation equals zero. The Carry flag is set when an instruction.
Binary Number Output To display a number in binary format, a program looks at each bit in the number and sends the ASCII equivalent of a ‘1’ (31h) or a.
21/11/2005CAP2411 Input & Output Instructions CPU communicates with the peripherals through I/O registers called I/O ports. There are 2 instructions, IN.
1 Logic, Shift, and Rotate Instructions Read Sections 6.2, 7.2 and 7.3 of textbook.
Assembly 05. Outline Bit mapping Boolean logic (review) Bitwise logic Bit masking Bit shifting Lookup table 1.
LEA instruction The LEA instruction can be used to get the offset address of a variable Example ORG 100h MOV AL, VAR1 ; check value of VAR1 by moving it.
Lecture 12 Integer Arithmetic Assembly Language for Intel-Based Computers, 4th edition Kip R. Irvine.
Irvine, Kip R. Assembly Language for Intel-Based Computers. Chapter 7: Integer Arithmetic Slides to Accompany Assembly Language for Intel-Based Computers,
CHAPTER 6 ARITHMETIC, LOGIC INSTRUCTIONS, AND PROGRAMS.
COMP 2003: Assembly Language and Digital Logic Chapter 2: Flags and Instructions Notes by Neil Dickson.
Computer and Information Sciences College / Computer Science Department CS 206 D Computer Organization and Assembly Language.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 251 Introduction to Computer Organization.
Boolean, Shift and Rotate instructions Dr.Hadi AL Saadi.
File Operations. FILE PROCESSING For the purposes of the following discussion, reading means copying all or part of an existing file into memory Writing.
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.
1 Chapter 6 Conditional Processing Assembly Language for Intel-Based Computers, 3rd edition Kip R. Irvine.
1st prog! Q: Read a char – from a keyboard & display it at the beginning of the next line! ====== A.
Instruksi Set Prosesor 8088
Microprocessor Architecture
Microprocessor and Assembly Language
EE3541 Introduction to Microprocessors
Instruction System - Bit Manipulation Instruction
Microprocessor and Assembly Language
Machine control instruction
Assembly Language Programming Part 2
4.4 Bit Manipulation Instructions
Chapter 4: Instructions
Microprocessor Lab CSL1543 0:0:2
תכנות בסיסי בשפת סף פרק 5 מצגת 3.
Shift & Rotate Instructions)
Shift & Rotate Instructions)
Shift, Multiply, and Divide
Arithmetic and Logic Chapter 5
High-level language structures
Computer Architecture and System Programming Laboratory
ARITHMETIC, LOGIC INSTRUCTIONS, AND PROGRAMS
Microprocessor and Assembly Language
Computer Organization and Assembly Language
By Nasser Halasa Assembly Language.
Shift and Rotate Instructions.
Computer Architecture and Assembly Language
Presentation transcript:

A Hexadecimal Calculator CALCUL.EXE A Hexadecimal Calculator

mov ah,0eh ;3- mov al,byte ptr hex_num+1 ;3- int 10h ;3- To display the MSB of v1

db = dw = db 12h db 34h dw 5678h dw 9ah dw bch

ASCII Code Table

Signed & unsigned numbers binary Decimal value 0111 0110 0101 0100 0011 0010 0001 0000 1111 1110 1101 1100 1011 1010 1001 1000 7 6 5 4 3 2 1 1 2 3 4 5 6 7 8 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00 (-2^3, 2^2, 2^1, 2^0)

MOV AH,D3 ; D3H = 10110011Y MOV CH,F1 ; F1H = 11110001Y ADD AH,CH MOV BH,6D ; 6DH = 01101011Y SUB BH,CH  AH = ? Y BH = ? Y

ASCII Code Table

; ################### ; # Procedure name: hex_dig ; # Function: To detect if al contains the ASCII code of a legal hexadecimal digit ; # Exit: CF = 0 if al is an ASCII code between '0' and '9', 'A' and 'F', or 'a' and 'f'. ; # CF = 1 otherwise ; # Register Changed: Flags (changed by CMP) hex_dig proc cmp al,'0' jb not_hex_dig cmp al,'9' jbe is_hex_dig not_0_to_9: cmp al,'A' cmp al,'F' not_A_to_F: cmp al,'a' cmp al,'f' not_hex_dig: stc ret is_hex_dig: clc hex_dig endp

ascii_to_hex proc cmp al,'0' jb not_hex_dig cmp al,'9' jbe is_0_to_9 ; ########################################### ; # Procedure name: ascii_to_hex ; # Function: Convert an ASCII code (one byte) to hexadecimal number (one nibble plus a leading zero nibble) ; # Entry: AL = the ASCII-coded hexadecimal digit ; # Exit: AL = the hexadecimal nibble with leading zero nibble ; # CF = 0 if al is an ASCII code between '0' and '9', 'A' and 'F', or 'a' and 'f'. ; # CF = 1 otherwise ; # Register Changed: AL, Flags (changed by CMP) ; # Example: Entry:: AL = '8' = 38H Exit:: AL = 08H ascii_to_hex proc cmp al,'0' jb not_hex_dig cmp al,'9' jbe is_0_to_9 not_0_to_9: cmp al,'A' cmp al,'F' jbe is_A_to_F_big not_A_to_F_big: cmp al,'a' cmp al,'f' jbe is_a_to_f not_hex_dig: stc ret is_0_to_9: sub al,'0' jmp is_hex_dig is_A_to_F_big: sub al,'A'-10 is_a_to_f: sub al,'a'-10 is_hex_dig: clc ascii_to_hex endp

; ########################################### ; # Procedure name: ascii_2digit_to_hex_1byte ; # Function: Convert a 2-digit ASCII code (two bytes) to a 1-byte hexadecimal number ; # Entry: AH = the higher digit of two ASCII-coded hexadecimal digits ; # AL = the lower digit of two ASCII-coded hexadecimal digits ; # Exit: AL = the two digits of the hexadecimal number ; # Register Changed: AH, AL, Flags ; # Example: Entry AX = '6a'; Exit AL = 6ah. ascii_2digit_to_hex_1byte proc call ascii_to_hex ;4- Convert the lower digit of the ASCII-coded hexadecimal number to a hexadecimal nibble rol ax,8 ;5- To exchange AH and AL. call ascii_to_hex ;6- Convert the higher digit of the ASCII-coded hexadecimal number to a hexadecimal nibble rol al,4 ;7- Move the left nibble to the right or al,ah ;8- Combine the two nibble ret ascii_2digit_to_hex_1byte endp

; ########################################### ; # Procedure name: hex_to_ascii ; # Function: Convert a hexadecimal number (one nibble plus a leading zero nibble) to an ASCII code (one byte) ; # Entry: AL = the hexadecimal nibble with leading zero nibble ; # Exit: AL = the ASCII-coded hexadecimal digit ; # Register Changed: AL, Flags (changed by CMP) ; # Example: Entry:: AL = 08H Exit: AL = '8' = 38H ; # Register changed: AL, Flags (changed by CMP or ADD) hex_to_ascii proc add al,30h cmp al,3ah jb below_a add al,61h - 3ah below_a: ret hex_to_ascii endp

; ########################################### ; # Procedure name: hex_1byte_to_ascii_2digit ; # Function: Convert a 1-byte hexadecimal number to a 2-digit ASCII code (two bytes) ; # Entry: AL = the two digits of the hexadecimal number ; # Exit: AH = the higher digit of two ASCII-coded hexadecimal digits ; # AL = the lower digit of two ASCII-coded hexadecimal digits ; # Register Changed: AH, AL, Flags ; # Example: Entry AL = 6ah; Exit AX = '6a' hex_1byte_to_ascii_2digit proc mov ah,al and ah,0fh shr al,4 call hex_to_ascii ;4- Convert the higher hexadecimal nibble to an ASCII-coded hexadecimal byte rol ax,8 ;5- To exchange AH and AL. call hex_to_ascii ;6- Convert the lower hexadecimal nibble to an ASCII-coded hexadecimal byte ret hex_1byte_to_ascii_2digit endp

mov hex_num,'00' ; To initialize hex_num get_1dig: mov ah,0eh ;3- ; ########################################### ; # Procedure name: get_hex_num_2dig ; # Function: Receive a 2-digit hexdecimal number from the keyboard ; # Exit: AX = the hexadecimal number ; # Note: '0' will lead user input get_hex_num_2dig proc pusha mov hex_num,'00' ; To initialize hex_num get_1dig: mov ah,0eh ;3- mov al,byte ptr hex_num+1 ;3- int 10h ;3- To display the MSB of v1 mov al,byte ptr hex_num ;3- int 10h ;3- To display the LSB of v1 mov ah,0 ;2- int 16h ;2- To recieve a key from the keyboard call hex_dig ;4- To distinguish hex and non-hex key jc hex_num_in ;4- Any non-hex-dig key will be treated as an "Enter" key mov ah,byte ptr hex_num ;7- New hex_num = LSB of old hex_num * 10H + entered digit mov hex_num,ax ;7- To save the new hex_num mov ah,0eh ;6- mov al,bs ;6- int 10h ;6- To go back one space jmp get_1dig hex_num dw '00' hex_num_in: popa mov ax,hex_num ret get_hex_num_2dig endp

mov ah,0eh ;6- mov al,bs ;6- int 10h ;6- To go back one space jmp get_1dig hex_num dw '00' hex_num_in: popa mov ax,hex_num ret get_hex_num_2dig endp