CSCI130 - PowerPoint PPT Presentation

1 / 13
About This Presentation
Title:

CSCI130

Description:

'unclaimed' quizzes. MM Address. Contents. 0 = 00000. 100 00101. LOAD 5. 1 = 00001. 110 00110 ... We prefer to use an English-like style (English mnemonics and ... – PowerPoint PPT presentation

Number of Views:49
Avg rating:3.0/5.0
Slides: 14
Provided by: usersC1
Category:

less

Transcript and Presenter's Notes

Title: CSCI130


1
Lecture 8
  • CSCI130
  • Instructor Dr. Imad Rahal

2
Announcements
  • Practice set 3
  • Exam 1 review set
  • unclaimed quizzes

3
(No Transcript)
4
Assembly Language
  • Machine code consists of the
  • binary instructions, data addresses
  • can directly be executed by the CPU
  • We as humans are not good in working with
    sequences of 1s and 0s
  • We prefer to use an English-like style (English
    mnemonics and decimal numbers)
  • This is called the assembly language
  • It has 1-to-1 correspondence to machine code
  • one instruction for every 3-bit Opcode and
    decimal numbers for addresses and data
  • Slight other changes

5
Assembly Language
  • Additional problems addressed
  • Most commands like LOAD, STOR, JUMP and ADD
    require memory addresses
  • How do we know which address in memory is free to
    use?
  • We also assumed that PC will contain 0 initially
  • Our program will be loaded to first memory
    locationis this always true?
  • What if we have multiple executing programs on
    the same machine?
  • Which will get the 0 address then?

6
Assembly Language
  • In reality, when we program, we dont concern
    ourselves with such low level details
  • More on this in the next chapter (OS)
  • From now on, we use variables/labels instead of
    addresses and totally forget about memory
  • 110 10010 ? ADD Counter which must initialized

7
Add all numbers between 1 and 10
  • Algorithm
  • Sum 0, decrement1, Limit10
  • Add limit to sum
  • Subtract decrement from Limit
  • If Limitgt0
  • Go back to step 2
  • Display sum
  • Stop

8
Assemblya nicer way to write the same thing
START LOAD SUM ADD LIMIT STOR
SUM LOAD LIMIT SUB DECREMENT STOR
LIMIT JPOS START LOAD SUM WRITE (
STOR 31) HALT SUM 0 DECREMENT 1 LIMIT
10
Changes 1- Use variables for needed data
holders 2- Use labels for jumps 3- WRITE for STOR
31 READ for LOAD 30
9
Add all numbers between 1 and N
  • Algorithm
  • Input N
  • Sum 0, decrement1, limit N
  • Add limit to sum
  • Subtract decrement from Limit
  • If Limitgt0
  • Go back to step 3
  • Display sum
  • Halt

10
Program to add all numbers between 1 and N
READ //instead of LOAD
30 STOR LIMIT LOOP LOAD SUM
ADD LIMIT STOR SUM LOAD LIMIT SUB
DECREMENT STOR LIMIT JPOS LOOP LOAD
SUM WRITE //instead of STOR 31 HALT SUM
0 DECREMENT 1 LIMIT 0
11
Assembly Language
  • Computers can only understand machine code
  • Programs written in assembly must be translated
    to machine code to be executable by CPU
  • The assembler is responsible for that
  • Stored in memory and executed before any assembly
    program can be executed
  • (english-like) assembly source code ? (binary)
    machine code
  • Does a lookup for each word (Opcodes)
  • Other things (find empty memory locations for my
    variables)
  • The result is called object code

12
Program to find the larger of two input numbers
  • 0 READ ( LOAD 30) loads 1st number
  • 1 STOR X store 1st number at location X
  • 2 READ loads 2nd number
  • 3 STOR Y store 2nd number at location Y
  • 4 SUB X subtract 1st from 2nd
  • 5 JPOS Y_LARGER if AC isgt0, then 2nd num is
    larger
  • 6 LOAD X otherwise, the 1st num is larger
  • 7 WRITE output first number
  • 8 HALT program is done
  • 9 Y_LARGER LOAD Y
  • 10 WRITE Output result
  • 11 HALT End program
  • 12 X 0 Initialize variables
  • 13 Y 0

13
More Practice
  • Algorithm and program to print all numbers
    between two user-input numbers N1 and N2
    inclusively (downwardsassume N2 gt N1)
Write a Comment
User Comments (0)
About PowerShow.com