LAB 5 Arithmetic Operations Simple Calculator

Similar documents
MODE (mod) FIELD CODES. mod MEMORY MODE: 8-BIT DISPLACEMENT MEMORY MODE: 16- OR 32- BIT DISPLACEMENT REGISTER MODE

Lecture 15 Intel Manual, Vol. 1, Chapter 3. Fri, Mar 6, Hampden-Sydney College. The x86 Architecture. Robb T. Koether. Overview of the x86

The x86 Architecture

EXPERIMENT WRITE UP. LEARNING OBJECTIVES: 1. Get hands on experience with Assembly Language Programming 2. Write and debug programs in TASM/MASM

UMBC. A register, an immediate or a memory address holding the values on. Stores a symbolic name for the memory location that it represents.

X86 Addressing Modes Chapter 3" Review: Instructions to Recognize"

LAB 4 Extending Signed and Unsigned Numbers

Computer Architecture and Assembly Language. Practical Session 3

Microprocessors & Assembly Language Lab 1 (Introduction to 8086 Programming)

Introduction to 8086 Assembly

Credits and Disclaimers

CSC 8400: Computer Systems. Machine-Level Representation of Programs

Assembly Language Each statement in an assembly language program consists of four parts or fields.

Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 2125: Assembly Language LAB

CS 31: Intro to Systems ISAs and Assembly. Martin Gagné Swarthmore College February 7, 2017

Binghamton University. CS-220 Spring x86 Assembler. Computer Systems: Sections

Arithmetic Instructions

complement) Multiply Unsigned: MUL (all operands are nonnegative) AX = BH * AL IMUL BH IMUL CX (DX,AX) = CX * AX Arithmetic MUL DWORD PTR [0x10]

8086 Programming. Multiplication Instructions. Multiplication can be performed on signed and unsigned numbers.

Mnem. Meaning Format Operation Flags affected ADD Addition ADD D,S (D) (S)+(D) (CF) Carry ADC Add with ADC D,C (D) (S)+(D)+(CF) O,S,Z,A,P,C

CSC 2400: Computer Systems. Towards the Hardware: Machine-Level Representation of Programs

We will first study the basic instructions for doing multiplications and divisions

Q1: Multiple choice / 20 Q2: Memory addressing / 40 Q3: Assembly language / 40 TOTAL SCORE / 100

Q1: Multiple choice / 20 Q2: Data transfers and memory addressing

SPRING TERM BM 310E MICROPROCESSORS LABORATORY PRELIMINARY STUDY

16.317: Microprocessor Systems Design I Spring 2014

Integer Arithmetic Part2

System calls and assembler

Credits and Disclaimers

CS 31: Intro to Systems ISAs and Assembly. Kevin Webb Swarthmore College February 9, 2016

mith College Computer Science CSC231 - Assembly Week #4 Dominique Thiébaut

CS 31: Intro to Systems ISAs and Assembly. Kevin Webb Swarthmore College September 25, 2018

Computer Architecture and System Programming Laboratory. TA Session 3

CS241 Computer Organization Spring 2015 IA

Instructions moving data

Addressing Modes on the x86

CSE2421 FINAL EXAM SPRING Name KEY. Instructions: Signature

Intel 8086: Instruction Set

Assembly Language Lab # 9

Lecture 9. INC and DEC. INC/DEC Examples ADD. Arithmetic Operations Overflow Multiply and Divide

Assembly Language: IA-32 Instructions

ECOM Computer Organization and Assembly Language. Computer Engineering Department CHAPTER 7. Integer Arithmetic

INSTRUCTOR: ABDULMUTTALIB A. H. ALDOURI

Week /8086 Microprocessor Programming I

Instruction Set Architecture (ISA) Data Types

We can study computer architectures by starting with the basic building blocks. Adders, decoders, multiplexors, flip-flops, registers,...

Lesson 1. Fundamentals of assembly language

Lab 2: Introduction to Assembly Language Programming

Access. Young W. Lim Sat. Young W. Lim Access Sat 1 / 19

ELEC 242 Time Delay Procedure

Basic Assembly Instructions

Module 3 Instruction Set Architecture (ISA)

IBM PC Hardware CPU 8088, Pentium... ALU (Arithmetic and Logic Unit) Registers. CU (Control Unit) IP.

Access. Young W. Lim Fri. Young W. Lim Access Fri 1 / 18

Registers. Ray Seyfarth. September 8, Bit Intel Assembly Language c 2011 Ray Seyfarth

Chapter 3: Addressing Modes

Inline Assembler. Willi-Hans Steeb and Yorick Hardy. International School for Scientific Computing

Computer Science Final Examination Wednesday December 13 th 2006

ADDRESSING MODES. Operands specify the data to be used by an instruction

EC 333 Microprocessor and Interfacing Techniques (3+1)

Signed number Arithmetic. Negative number is represented as

Computer Processors. Part 2. Components of a Processor. Execution Unit The ALU. Execution Unit. The Brains of the Box. Processors. Execution Unit (EU)

Chapter 7 Integer Arithmetic

Introduction to IA-32. Jo, Heeseung

Turning C into Object Code Code in files p1.c p2.c Compile with command: gcc -O p1.c p2.c -o p Use optimizations (-O) Put resulting binary in file p

INTRODUCTION TO IA-32. Jo, Heeseung

mith College Computer Science CSC231 Assembly Week #5 Fall 2017 Dominique Thiébaut

16.317: Microprocessor Systems Design I Fall 2013

The Microprocessor and its Architecture

Integer Arithmetic. Computer Organization and Assembly Languages Yung-Yu Chuang 2005/11/17. with slides by Kip Irvine

Interfacing Compiler and Hardware. Computer Systems Architecture. Processor Types And Instruction Sets. What Instructions Should A Processor Offer?

Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 2125: Assembly Language LAB. Lab # 7. Procedures and the Stack

Basic Execution Environment

Integer Arithmetic. Shift and rotate. Overview. Shift and Rotate Instructions

CS165 Computer Security. Understanding low-level program execution Oct 1 st, 2015

22 Assembly Language for Intel-Based Computers, 4th Edition. 3. Each edge is a transition from one state to another, caused by some input.

Q1: Multiple choice / 20 Q2: Protected mode memory accesses

Marking Scheme. Examination Paper Department of CE. Module: Microprocessors (630313)

Instruction Set Architectures

Defining and Using Simple Data Types

Basic Pentium Instructions. October 18

Add Subtract Multiply Divide

Machine/Assembler Language Putting It All Together

Lecture (07) x86 programming 6

EEM336 Microprocessors I. Addressing Modes

Integer Arithmetic. Pu-Jen Cheng. Adapted from the slides prepared by Kip Irvine for the book, Assembly Language for Intel-Based Computers, 5th Ed.

Reverse Engineering II: The Basics

Lecture 3: Instruction Set Architecture

CSE351 Spring 2018, Midterm Exam April 27, 2018

Assembler Programming. Lecture 2

Practical Malware Analysis

CMSC 313 Lecture 07. Short vs Near Jumps Logical (bit manipulation) Instructions AND, OR, NOT, SHL, SHR, SAL, SAR, ROL, ROR, RCL, RCR

6/20/2011. Introduction. Chapter Objectives Upon completion of this chapter, you will be able to:

Faculty of Engineering Computer Engineering Department Islamic University of Gaza Assembly Language Lab # 2 Assembly Language Fundamentals

x86 Assembly Tutorial COS 318: Fall 2017

Complex Instruction Set Computer (CISC)

Lab 4: Basic Instructions and Addressing Modes

CMSC Lecture 03. UMBC, CMSC313, Richard Chang

Instruction Set Architectures

MACHINE-LEVEL PROGRAMMING I: BASICS COMPUTER ARCHITECTURE AND ORGANIZATION

Transcription:

LAB 5 Arithmetic Operations Simple Calculator Objective: Practice arithmetic operation for the 80x86, such as add, subtract, multiple, divide, and mod. When dealing with the multiply, divide, and mod instructions on the 80x86, you must use the AL/AX/EAX and DX/EDX registers. You cannot use arbitrary registers as you can with other operations, such as addition and subtraction. Learn how to write a function in the programming. Use ASM (a computer assembly language program) to write the computer programs. You studied eight 32-bit registers that have the following names: EAX, EBX, ECX, EDX, ESI, EDI, EBP, and ESP; the eight 16- bit registers that have the following names: AX, BX, CX, DX, SI, DI, BP, and SP; and eight 8-bit registers that have the following names: AL, AH, BL, BH, CL, CH, DL, and DH. Design your programming to complete the following arithmetic operation with signed number and unsigned number: The output of program will have a main menu asking the user to 1 Signed Integer Arithmetic Operation (16-bit) 2 Exit After you choose the main menu 2, the program will exit the program. After you choose the main menu 1, a submenu will ask the user to select a. Input two 16-bit signed number operands for addition, and display the sum in the format of decimal and hexadecimal number, respectively. b. Input two 16-bit signed number operands for subtraction and display the difference in the format of decimal and hexadecimal number, respectively. c. Input two 16-bit signed number operands for multiplication and display the product in the format of decimal and hexadecimal number, respectively. d. Input two 16-bit signed number operands for division and display the quotient in the format of decimal and hexadecimal number, respectively (option). e. Input two unsigned number operands for addition, and display the sum in the format of decimal and hex, respectively 1

f. Input two unsigned number operands for subtraction and display the difference in the format of decimal and hex, respectively. g. Input two unsigned number operands for multiplication and display the product in the format of decimal and hex, respectively. h. Input two unsigned number operands for division and display the quotient and remainder in the format of decimal and hex, respectively. After selecting each of the submenus, for example, user selects the submenu of (b), the program asks the user to enter the two numbers. After successful performing the operations, the program will display results in the output: For example, Enter the first sighed integer number in decimal format (for example 12): Enter the second sighed integer number in decimal format (for example -2): For the decimal format, the sum of the 12 and -2 is 10. The identical Hex value for decimal value 10 is 0x000A shown in 16-bit (you may show this information by cout<<hex<< value) The program will ask the user Continue your integer calculator Y/N, enter 'Y' or 'N' If the user chooses Y or y, the program will return to main menus; if the user chooses N or n, the program will exit the program. 2

Background: Type Instruction Example Meaning Addition ADD ADD AX, 0x7b AX <- AX+7B INC INC BX BX <- BX+1 Subtraction SUB SUB CL, 0xA CL <- CL-A DEC DEC CX CX <- CX-1 NEG NEG CX CX <- 0-CX Multiplication MUL (unsigned multiply) MUL CL MUL CX unsigned AX <- AL*CL unsigned (DX::AX) <- AX*CX IMUL (signed multiply) IMUL CL signed AX <- AL*CL IMUL op16 signed (DX::AX) <- AX*op16 Division Performs both division and modulus operations DIV (Unsigned divide) DIV BH unsigned AL <- Q(AX/BH) AH <- R(AX%BH) DIV op16 unsigned AX <- Q( DX::AX/ op16 ) DX <- R(DX::AX % op16) IDIV (signed divide) IDIV BH signed AL <- Q(AX/BH) AH <- R (AX%BH) IDIV op16 signed AX <- Q( DX::AX / op16 ) DX <- R(DX::AX % op16) 3

Review how to write source code from previous lab. In this lab, you can follow the sample code to write your source code //part of calculator source code //calculator.cpp #include <stdio.h> #include <iostream> using namespace std; void addition (short int x, short int y); // addition for signed integers void subtraction (short int x, short int y); // subtraction for signed integers void multiplication (short int x, short int y); // multiplication for signed integers void division ( int x, short int y); // division for signed integers void addition (unsigned short int x, unsigned short int y); // addition for unsigned integers void subtraction (unsigned short int x, unsigned short int y); // subtraction for unsigned integers void multiplication (unsigned short int x, unsigned short int y); // multiplication for unsigned integers void division ( unsigned int x, unsigned short int y); // division for signed integers int main() //more variables should be declared char ch1, ch2, ch3; unsigned short ur1, ur2, ur; signed short r1, r2, r; // more declaration here cout << "Start your calcalator Y/N, enter 'Y (or y)' or 'N( or n)' "<< endl; cin>> ch1; ch1 = ch1; while (ch1=='y' ch1=='y') printf ("Menu:\n"); printf ("1, 16-bit Integer Arithmetic Operation\n"); printf ("2, Exit\n"); printf ("Menu Options:\n "); std::cin >> ch2; ch2 = ch2; //Submenu: if (ch2=='1') printf ("Submenu - input your choice\n"); printf ("(a) Input two signed number operands for addition, and display the sum in the format of decimal and hex, respectively.\n"); printf ("(b) Input two signed number operands for subtraction and display the difference in the format of decimal and hex, respectively.\n"); printf ("(c) Input two signed number operands for multiplication and display the product in the format of decimal and hex, respectively.\n"); printf ("(d) Input two signed number operands for division and display the quotient and remainder in the format of decimal and hex, respectively.\n"); 4

printf ("(e) Input two unsigned number operands for addition, and display the sum in the format of decimal and hex, respectively.\n"); printf ("(f) Input two unsigned number operands for subtraction and display the difference in the format of decimal and hex, respectively.\n"); printf ("(g) Input two unsigned number operands for multiplication and display the product in the format of decimal and hex, respectively.\n"); printf ("(h) Input two unsigned number operands for division and display the quotient and remainder in the format of decimal and hex, respectively.\n"); else goto EndLable ; std::cin >> ch3; ch3 = ch3; //your code for signed number and unsighed number arithmatic operations switch (ch3) case 'a': printf ("Input two signed number operands in decimal format\n"); scanf_s("%d %d", &r1, &r2); //read two signed numbers from keyboard addition (r1, r2); printf ("======================================================\n"); break; case 'b': printf ("Input two signed number operands in decimal format\n"); scanf_s("%d %d", &r1, &r2); //read two signed numbers from keyboard subtraction (r1, r2); printf ("======================================================\n"); break; // continue your source code cout << "Continue your integer calculator Y/N. Enter: 'Y' or 'N' "<< endl; cin>> ch1; ch1 = ch1; EndLable: cout << "Exit program"<< endl; //getchar(); system ("pause"); //hold screen return 0; void addition (short int x, short int y) short int r; 5

_asm MOV AX, x; MOV BX, y; ADD AX, BX; MOV r, AX; cout<< "The decimal sum of "<<x <<" and "<<y << " is " << r<< endl; cout<< "The hexadecimal sum of "<<hex<<x <<" and "<< hex<< y << " is " << hex<< r<< endl; void subtraction (short int x, short int y) short int r; _asm MOV AX, x; MOV BX, y; SUB AX, BX; MOV r, AX; cout<< "The decimal subtraction of "<<x <<" minus "<<y << " is " << dec<< r<< endl; cout<<"the hexadecimal subtraction of "<< hex<<x <<" minus " <<hex<<y << " is " <<hex<<r<< endl; // continue your source code for each function declared at the top of the programming // continue your source code for each function declared at the top of the programming void multiplication (short int x, short int y) // multiplication for signed integers void division ( int x, short int y) // division for signed integers void addition (unsigned short int x, unsigned short int y) // addition for unsigned integers void subtraction (unsigned short int x, unsigned short int y) // subtraction for unsigned integers void multiplication (unsigned short int x, unsigned short int y) // multiplication for unsigned integers void division ( unsigned int x, unsigned short int y) // division for signed integers 6