0% found this document useful (0 votes)
85 views

Assembler Language I

This document provides an introduction to assembler language and discusses numbers in different bases such as decimal, binary, and hexadecimal. It covers converting between these number bases and arithmetic with signed and unsigned binary numbers. Main storage organization and the representation of signed binary integers using two's complement notation is also explained.

Uploaded by

jayakkannan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
85 views

Assembler Language I

This document provides an introduction to assembler language and discusses numbers in different bases such as decimal, binary, and hexadecimal. It covers converting between these number bases and arithmetic with signed and unsigned binary numbers. Main storage organization and the representation of signed binary integers using two's complement notation is also explained.

Uploaded by

jayakkannan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 42

Assembler Language

"Boot Camp"
Part 1 - Numbers and
Basic Arithmetic
SHARE in Minneapolis
July 22 - 27, 2001
Session 8181

1
Introduction
Who are we?

John Dravnieks, IBM

John Ehrman, IBM

Michael Stack, Northern Illinois University

2
Introduction
Who are you?
An applications programmer who needs to write
something in S/390 assembler?
An applications programmer who wants to
understand S/390 architecture so as to better
understand how HLL programs work?
A manager who needs to have a general
understanding of assembler?

Our goal is to provide for professionals a brief


introduction to the S/390 assembly language
3
Introduction
These sessions are based on notes of a course in
assembler language at Northern Illinois University

The notes are in turn based on the textbook,


Assembler Language with ASSIST and ASSIST/I by
Ross A Overbeek and W E Singletary, Fourth
Edition, published by Macmillan

4
Introduction
The original ASSIST (Assembler System for
Student Instruction and Systems Teaching) was
written by John R Mashey at Penn State University

ASSIST/I, the PC version of ASSIST, was written


by Bob Baker, Terry Disz and John McCharen at
Northern Illinois University

Both ASSIST and ASSIST/I are in the public


domain, and are compatible with the System/370
architecture of about 1975 (fine for beginners) 5
Introduction
Both ASSIST and ASSIST/I are available at
http://mstack.cs.niu.edu/pub/assist

Other materials described in these sessions can


be found at the same site, at
http://mstack.cs.niu.edu/pub/share

Disclaimer: please keep in mind that neither Penn


State nor NIU are able to provide support for
ASSIST or ASSIST/I
6
Introduction
Other references used in the course at NIU are:
Principles of Operation
System/370 Reference Summary
High Level Assembler Language Reference

Access to PoO and HLASM Ref is normally online

Students use the white "green card" booklet all


the time, including during examinations
(SA22-7209)
7
Our Agenda for the Week
Session 8181: Numbers and Basic Arithmetic

Session 8182: Instructions and Addressing

Session 8183: Assembly and Execution; Branching

Session 8184: Arithmetic; Program Structures

Session 8185: Decimal and Logical Instructions

8
Today's Agenda
Decimal, Binary and Hexadecimal Numbers and
Conversions

Main Storage Organization and Signed Binary


Numbers

Integer Arithmetic and Overflow

Getting Started with ASSIST/I

9
Decimal, Binary and
Hexadecimal
Numbers and
Conversions
In Which We Learn to Count
All Over Again

10
Counting in Bases 10, 2, and 16
Dec Bin Hex Dec Bin Hex
0 0000 0 8 1000 8
1 0001 1 9 1001 9
2 0010 2 10 1010 A
3 0011 3 11 1011 B
4 0100 4 12 1100 C
5 0101 5 13 1101 D
6 0110 6 14 1110 E
7 0111 7 15 1111 F
16 10000 10 11
Numbers in Different Bases
Consider how we write numbers in base 10, using
the digits 0 - 9:
83210 = 80010 + 3010 + 210
= 8 x 102 + 3 x 101 + 2 x 100

For numbers in base 2, we need only 0 and 1:


11012 = 10002 + 1002 + 00 + 1
= 1 x 23 + 1 x 22 + 0 x 21 + 1 x 20

But because it requires less writing, we usually


prefer base 16 to base 2 12
Caution!
The value of a number may be ambiguous when the
base isn't provided

1011 = ?10

10112 = 1110

101116 = 411310

The base will usually be clear from the context, but


will otherwise be provided
13
Converting Bin & Hex to Decimal
3
10112 = 1x2 = 1x8 =8
2
+ 0x2 = 0x4 =0
1
+ 1x2 = 1x2 =2
0
+ 1x2 = 1x1 =1
11

2
A6116 = 10 x 16 = 10 x 256 = 2560
1
+ 6 x 16 = 6 x 16 = 96
0
+ 1 x 16 = 1 x 1 = 1
2657

Note that all numbers without subscript are base 10


14
Converting Decimal to Bin & Hex
To convert a decimal number n to base b
1. Divide n by b, giving quotient q and remainder r
2. Write r as the rightmost digit, or as the digit to the
left of the last one written
3. If q is zero, stop; otherwise set n <--- q and go to 1

Note that each digit will be in the range 0 to b-1

15
Example: Convert 12310 to Base 16
123 / 16 = 7 with remainder 11, so the rightmost
digit is B

7 / 16 = 0 with remainder 7 so the next digit to


the left is 7

Since quotient is 0, stop

Result is 12310 = 7B16

A similar process shows 12310 = 11110112 16


Conversions Between Bin and Hex
These are the easiest of the conversions, because
4
16 = 2 and we can convert by groups of digits

To convert from binary to hexadecimal

1. Starting at the right, separate the digits into groups


of four, adding any needed zeros to the left of the
leftmost digit so that all groups have four digits

2. Convert each group of four binary digits to a


hexadecimal digit
17
Conversions Between Bin and Hex
So to convert 101101 to hex,
1. Group the digits and add zeros: 0010 1101
2. Convert to hex digits: 2 D

To convert from hexadecimal to binary, simply


reverse the algorithm

So 2C5 = 0010 1100 0101 = 1011000101

18
Arithmetic with Unsigned Numbers
Addition and subtraction of unsigned numbers is
performed in hexadecimal and binary just the
same as it is in decimal, with carries and borrows

We normally use signed numbers, so we won't


dwell on these

19
Arithmetic with Unsigned Numbers
1101 <--- carries 11110 <--- carries
FCDE 10110
+ 9A05 + 1011
196E3 100001

BD+c <--- borrows 0110+c <--- borrows


FCDE 111000
-9AE5 - 10011
61F9 100101

20
Main Storage
Organization and
Signed Binary
Numbers

21
Main Storage Organization
In order to understand how signed numbers are
represented in a binary computer, we need first
to understand memory organization

Abstractly, a binary digit (or bit) can be


represented by any 2-state system: on-off,
true-false, etc.

A computer's memory is simply a collection of


millions of such systems implemented using
electronic switches 22
Main Storage Organization
Memory is organized by grouping eight bits into a
byte, then assigning each byte its own identifying
number, or address, starting with zero

Bytes are then aggregated into words (4 bytes),


halfwords (2 bytes) and doublewords (8 bytes)

So
One byte = eight bits
One word = four bytes = 32 bits
23
Main Storage Organization
Typically, each of these aggregates is aligned on an
address boundary which is evenly divisible by its
size in bytes

So, a fullword (32 bits) is aligned on a 4-byte


boundary (addresses 0, 4, 8, 12, 16, 20, etc.)

Remember, memory addresses refer to bytes, not


bits or words

24
Representation of Signed Binary
Integers
Representing unsigned binary integers was fairly
simple, but how can we include a sign?

There are three ways we might represent negative


integers, using a single bit as the sign
Signed-magnitude
Ones' complement
Two's complement

It is customary that the leftmost bit is the sign


25
Representation of Signed Binary
Integers
Signed-magnitude is the most familiar (+17, -391)
and we will see later how this is used in S/390

Allocating an extra bit for the sign, since 910 = 10012,


we would write +9 as 0 10012 and -9 as 1 10012

The ones' complement of a number is found by


replacing each 1 with 0 and each 0 with 1

If we use one bit for the sign, then since 910 is 10012,
we would write +9 as 0 10012 and -9 as 1 01102
26
Representation of Signed Binary
Integers
The two's complement representation is formed
by taking the ones' complement and adding 1

In this notation, again using one bit for the sign, we


write +9 as 0 10012 and -9 as 1 01112

In the S/390, a negative binary integer is


represented by the two's complement of its
positive value

Note that zero is its own complement in this


representation (no +0 or -0) 27
Representation of Signed Binary
Integers
In S/390, integers are represented in a 32-bit
fullword, using the first bit as the sign

A fullword can contain non-negative integers in


31
the range 0 to 2 -1 (with sign bit = 0)
31
A negative integer in the range -2 +1 to -1 (with
sign bit = 1) is formed by taking the two's
complement of its absolute value

28
Representation of Signed Binary
Integers: Examples
31
-2 is represented by 1000...000 but this number
is not the two's complement of any positive
integer

In two's complement representation we have


+1 = 00000000 00000000 00000000 00000001
-1 = 11111111 11111111 11111111 11111111

Or, in the more commonly used hexadecimal


+1 = 00000001
-1 = FFFFFFFF 29
Integer Arithmetic
and Overflow

30
Arithmetic with Signed Numbers
Let's look at examples of addition and subtraction
using signed numbers in two's complement. These
examples use only 4 bits, one for sign, three for value.

+3 = 0 011
+2 = 0 010
+5 0 101

+3 = 0 011
-2 = 1 110 (Two's complement of 0 010)
+1 0 001 (Note that the carry out is ignored)
31
Arithmetic with Signed Numbers
Now, how about -3 plus +2:
-3 = 1 101
+2 = 0 010
-1 1 111

Notice that the sign is correct each time, and the


result is also in two's complement notation.

Also, subtraction is performed by adding the two's


complement of the subtrahend to the minuend.
That is, +3 - +2 = +3 + (-2). 32
Arithmetic with Signed Numbers
Computer arithmetic using 32-bit fullwords is a bit
more complex, and is always shown in hex. Also, we
will no longer show a separate sign bit:
00000011 AE223464
+0000010B +5FCA5243
0000011C 0DEC86A7

F89ABCDE F89ABCDE
-6D4AFBC0 = +92B50440 (Add 2's comp)
8B4FC11E
Note that carry bits are discarded (result is correct
anyway) 33
Overflow
What if two large numbers are added and the
31 31
result is greater than 2 -1 (or less than -2 )?

And how can we tell if this happened?

In order to understand this, we will demonstrate


with our very small "words" consisting of four bits,
the first of which is the sign

These "4-bit words" can handle integers in the


range from -8 to +7 (1 000 to 0 111)
34
Overflow
Now let's see what happens when we try to add
+5 to +4 (we'll do this in binary, using our
four-bit words).

Overflow will occur since the result is greater than


+7.

This is detected by checking the carry into the sign


position and the carry out of the sign position:
If they are not equal, overflow occurred and the
result is invalid. 35
Overflow
Out In [not equal, so overflow occurred]
\ /
01 00 <--- carries
0 101 = +5
0 100 = +4
1 001 = invalid result (overflow occurred)

The program may or may not take action on


overflow, but it normally should since the result is
invalid
36
Overflow
But be very careful! The S/390 is a binary computer,
not hexadecimal, so the check for overflow must be
done using the binary representation (the sign is a bit,
not a hex digit). So if we add
1111...
D13BCF24 D = 1101...
+F3C12B97 F = 1111...
1100...
we check the leftmost bits for overflow and find that
none has occurred (but try checking using hex, and
you'll see why it doesn't work!) 37
Getting Started With
ASSIST/I

38
ASSIST/I Features
ASSIST/I is an integrated assembler and instruction
interpreter, plus a text editor and interactive
debugger

There are built-in functions (X-instructions) for


I/O and data conversion

Program tracing lets you watch "everything"


happen

39
ASSIST/I Features
It is a useful tool for getting started and "tinkering"
on a PC without needing any host-system access

A User Guide is included in the "Starter Kit"


handout

And it's free!

40
ASSIST/I Limitations
ASSIST/I supports only an older, less-rich
instruction set

Modern assembler features are missing

Programming style may be less robust than desired

Text editor functions are rather awkward


It may be easier to use a simple PC editor

System macros aren't available 41


Getting Started with ASSIST/I
Easiest: run everything from the diskette
Change your disk drive to A: and your working
directory to \BootAsst\
Enter CAS, and follow the prompts to run
program DEMOA.ASM
We'll step through its execution and show how
to create a .PRT file

Try some of the other DEMO programs

42

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy