Sei sulla pagina 1di 16

Department of Computer

Assembly Language learning

J
1) Stage (Journey inside-out the concept)
2) Stagea1(Apply the learned)
3) Stagev (Verify the accuracy)
4) Stagea2(Assess your work)

COMSATS Institute of Information


1 Technology (CIIT)
Islamabad
Table of Contents

Lab Topics Covered Page


# #
Lab # Data Representation: Conversions in Java 4
01
Lab # Instruction set architecture (16 bits): Design and
02 Working

Lab # Debug Tool and Usage of software Interrupt (INT


03 command)

Lab # Assembly Language Introduction; MASM configuration;


04 Usage of Dumpregs;
Input and Output in Assembly using Call WriteTYPE and
Call ReadTYPE
Lab # Data Types in Assembly: BYTE, WORD and DWORD
05
Lab # Data Transfer and Arithmetic Instructions; Flag affected
06 by arithmetic;
Data Related operators
Lab # Array Processing (Direct, Indexed and Indirect); LOOP
07 and Nested LOOP

Lab # Introduction to Procedures; User defined Procedures;


08 Procedures having flexibility
Lab # Boolean Operations: AND, OR, NOT, XOR, TEST and CMP
09
Lab # Flow Control and Conditional Jump Instructions: Signed
10 Vs. Unsigned

Lab # Implementation of HLL Control Structures


11
Lab # Shift: Logical and Arithmetic; Signed and Unsigned Shift;
12 Rotate Instructions (Left or Right and Others)
Lab # Multiplication Instructions; MUL and IMUL; Applications
13 of Multiplication

Lab # Division Instructions; DIV and IDIV; Applications of


14 Division

Terminal Examination

2
3
LAB # 01

Statement Purpose:
This lab will give you practical implementation of conversions and arithmetic on unsigned and
signed integers and real numbers among different radices of decimal, binary, and hexadecimals using
programs in JAVA.

Activity Outcomes:
This lab teaches you the following topics:

Conversions between different radices.


Representations of signed and unsigned integer numbers.
Representation of floating pint numbers.
Arithmetic operations on numbers of all types.

Instructor Note:
As pre-lab activity, read Chapter 1 section 1.3 from the book (Assembly Language for X86
processors, KIP R. IRVINE., 7th Edition (2015), Pearson), and also as given by your theory
instructor.

4
1) StageJ(Journey)
Introduction
Everything suited for processing with digital computers is represented as a sequence of 0s and 1s,
whether it be numeric data, text, executable files, images, audio, or video. The meaning of a given
sequence of bits within a computer depends on the context. In this section we describe how to
represent integers in binary, decimal, and hexadecimal and how to convert between different
representations. We also describe how to represent negative integers and floating-point numbers

2) Stage a1 (apply)
Lab Activities:

Activity 1:
Hexadecimal to decimal and binary conversion, This Java program will convert Hexadecimal
number to decimal, binary and Octal in Java programming language using JDK standard API
methods. For beginners hexadecimal is base 16 number, while decimal is base 10, Octal is base 8
and binary is base 2 numbers in Number systems. Binary only contains 0 and 1 bits, octal contains 0
to 7, decimal contains 0 to 9 and Hexadecimal contains 0-9, A, B, C, D, E, F where F represent 15.
Thankfully Java library provides convenient method to convert any integer fromone number system
to another.

Solution:
Java API provides two methods which is used in converting number from one number system to
other. One is Integer.parseInt() which is used to convert String to Integer in Java but also allows you
to specify radix.

* Java program to convert Hexadecimal to binary, decimal and Octal in Java.


* Hexadecimal is base 16, Decimal number is base 10, Octal is base 8
* and Binary is base 2 number which has just two numbers 0 and 1.
* @author
*/
public class ConvertHexaToDecimal {
public static void main(String args[]) {
// Ask user to enter an Hexadecimal number in Console
System.out.println("Please enter Hexadecimal number : ");
Scanner scanner = new Scanner(System.in);

String hexadecimal = scanner.next();

5
//Converting Hexa decimal number to Decimal in Java
int decimal = Integer.parseInt(hexadecimal, 16);

System.out.println("Converted Decimal number is : " + decimal);

//Converting hexa decimal number to binary in Java


String binary = Integer.toBinaryString(decimal);
System.out.printf("Hexadecimal to Binary conversion of %s is %s %n", hexadecimal,
binary );

// Converting Hex String to Octal in Java


String octal = Integer.toOctalString(decimal);
System.out.printf("Hexadecimal to Octal conversion of %s is %s %n", hexadecimal, octal );
}
}

Output:
Please enter Hexadecimal number :
A
Converted Decimal number is : 10
Hexadecimal to Binary conversion of A is 1010
Hexadecimal to Octal conversion of A is 12

Activity 2:

Example shows how to convert binary to decimal in


JAVA.

Solution:
Create Java Main Class and named it Binary_Decimal.
Copy the Code and test it by running the application

import java.util.Scanner;

public class Binary_Decimal {

Scanner scan;

int num;

6
void getVal() {

System.out.println("Binary to Decimal");

scan = new Scanner(System.in);

System.out.println("\nEnter the number :");

num = Integer.parseInt(scan.nextLine(), 2);

void convert() {

String decimal = Integer.toString(num);

System.out.println("Decimal Value is : " + decimal);

class MainClass {

public static void main(String args[]) {

Binary_Decimalobj = new Binary_Decimal();

obj.getVal();

obj.convert();

Activity 3:
The example below, how to convert from binary to
Octal in JAVA.

7
import java.util.Scanner;

public class Binary_Octal {

Scanner scan;

int num;

void getVal() {

System.out.println("Binary to Octal");

scan = new Scanner(System.in);

System.out.println("\nEnter the number :");

num = Integer.parseInt(scan.nextLine(), 2);

void convert() {

String octal = Integer.toOctalString(num);

System.out.println("Octal Value is : " + octal);

class MainClass {

public static void main(String args[]) {

Binary_Octalobj = new Binary_Octal();

obj.getVal();

obj.convert();

8
Activity 4:
Here it is demonstrated how to convert from binary
to hexadecimal.
Solution:
import java.util.Scanner;

public class Binary_Hexa {

Scanner scan;

int num;

void getVal() {

System.out.println("Binary to Hexadecimal");

scan = new Scanner(System.in);

System.out.println("\nEnter the number :");

num = Integer.parseInt(scan.nextLine(), 2);

void convert() {

String hexa = Integer.toHexString(num);

System.out.println("Hexadecimal Value is : " + hexa);

class MainClass {

9
public static void main(String args[]) {

Binary_Hexaobj = new Binary_Hexa();

obj.getVal();

obj.convert();

Activity 5:
Here your job is to write a function that takes an
integer input and returns the number of 1's in its
binary representation.
Solution:

public static int bitCount(int input) {

int count = 0;

for (int i = 0; i< 32; i++)

count = count + (input >>>i& 1);

return count;

public static int bitCount(int x) {

if (x == 0) return 0;

10
return (x & 1) + bitCount(x >>> 1);

This is how Integer.bitCount() is implemented by Java. See if you can figure out how it works.

public static int bitCount(int i) {

i = i - ((i>>> 1) & 0x55555555);

i = (i& 0x33333333) + ((i>>> 2) & 0x33333333);

i = (i + (i>>> 4)) & 0x0f0f0f0f;

i = i + (i>>> 8);

i = i + (i>>> 16);

return i& 0x3f;

11
Stagev(verify)

Home Activities:
Activity 1:
Covert the following programs Pseudo-code in
JAVA.Just use the algorithms given in activity.
1. Conversion from base 2 and base 16 numbers to Decimal

2. Conversion from decimal number to base 2 and base 16

12
3. Conversion of ay Binary fraction to Decimal

13
4. Conversion of decimal Fraction to Binary

14
5. Decimal number to Floating Point Binary Representation

15
3) Stagea2(assess)
Demonstrate the home activities and Viva voce

16

Potrebbero piacerti anche