cis 020 assembly programming chapter 10 - understanding the assembly process © john urrutia 2012,...

40
CIS 020 Assembly Programming Chapter 10 - Understanding the Assembly Process © John Urrutia 2012, All Rights Reserved. 5/27/2012 1

Upload: randell-harvey

Post on 03-Jan-2016

216 views

Category:

Documents


0 download

TRANSCRIPT

PowerPoint Presentation

CIS 020 Assembly ProgrammingChapter 10 - Understanding the Assembly Process John Urrutia 2012, All Rights Reserved.5/27/20121ObjectivesReading and interpreting assembly listingsThe translation processTechniques for desk checking programsCorrecting syntax errorsCorrecting logic errorsCorrecting common runtime errors John Urrutia 2012, All Rights Reserved.25/27/2012Tips for Program DevelopmentPlanning Never ever, ever code a program without first documenting what you are going to do.Identify and document the output Spend plenty of time understanding what the output should look like and validate this the userThe input Where is the data coming from, will it be reliable, does it contain all of the necessary element to create the outputThe process Create pseudo-code or structured English, create a detailed flowchart John Urrutia 2012, All Rights Reserved.35/27/2012Tips for Program DevelopmentPlanning Once you have finished the documentation Validate your understanding Meet with representatives of all user groups that will use this program.Make corrections If you have missed or misinterpreted the users needs correct and re-validate.Begin Initial coding Start the translation process from documentation into code segments, assemble the code, correct any syntax errors. John Urrutia 2012, All Rights Reserved.45/27/2012Tips for Program DevelopmentDesk Checking a Program Take the role of the computer Create a single set of input data to be processed by your programCreate the expected output based on your current understandingUsing the input and your program listing mentally execute each instruction and create the outputCompare the output from your desk check with the expected output Look for possible gaps in your logic or data. John Urrutia 2012, All Rights Reserved.55/27/2012Tips for Program DevelopmentStructured Walkthroughs Present you program to the other members of the team.Identify areas you think my be troublesome.Solicit ideas for streamlining or improving your code.Leverage the experience of the other team members.Walkthroughs are usually critical evaluations of your work.Be careful not to over-react to constructive criticisms, you will have the same responcibility.More eyes on a problem will significantly create a better solution with less debugging time.

John Urrutia 2012, All Rights Reserved.65/27/2012Tips for Program DevelopmentProgrammer TeamsTeamwork is the difference betweenBeing on-time and within budgetVersusBeing somewhere you dont want to be. John Urrutia 2012, All Rights Reserved.75/27/2012The Assembly ProcessOnce you have coded a programIt is in a text format and needs to be translatedThe Assembler program does the translation and produces An assembler listing of your source programInstruction translationsCross-reference & DiagnosticsAn object module a non-executable machine language equivalent of your source program

John Urrutia 2012, All Rights Reserved.85/27/2012The Assembly ProcessOnce the program has successfully AssembledThe object module is converted to a load module by the linkage editor program which resolves all external references such as:ConsoleMonitorDisk driveNetwork John Urrutia 2012, All Rights Reserved.95/27/2012The Assembly ProcessOnce the program has successfully Link Edited we are ready to execute the module in a testing mode.We need to create our test plan which takes into consideration: All branch pointsDomain of variablesExceptional conditions John Urrutia 2012, All Rights Reserved.105/27/2012The Assembly ProcessAn abbreviated example test plan for a date entry

John Urrutia 2012, All Rights Reserved.115/27/2012

The Assembly ProcessAn abbreviated example test plan for a date entry

See Chap 10 - DateType Test Plan.doc

John Urrutia 2012, All Rights Reserved.125/27/2012

The Assembly ProcessAs the Assembler assembles:Creates address locations for instructionsCreates address locations for labels Branch Points, Variables, ConstantsCreates address locations for External references

So, what is an address?It is the hexadecimal value that represents the storage location in the computers main memory or primary storage. John Urrutia 2012, All Rights Reserved.135/27/2012The Assembly ProcessSo, what is an address?It is the hexadecimal value that represents the storage location in the computers main memory or primary storage.Memory that you have access to is called Addressable and by default in our environment is limited to 24 bitsGiving us 3 bytes worth of unique addresses Hex values 000000 though FFFFFF or 16MB (16,777,216) address locations for us to use John Urrutia 2012, All Rights Reserved.145/27/2012The Assembly ProcessWhen we assemble a program the Assembler always starts at address 000000 and increments the address for each of the elements in the programe.g. Address 000000 MVC FIELD2,FIELD1 000006 FIELD1 DC CL1'? 000007 FIELD2 DS CL8 00000F END John Urrutia 2012, All Rights Reserved.155/27/2012The Assembly ProcessNotice the address of the MVC instruction is 000000 The Address for FIELD1 is 000006 which means the MVC instruction is 6 bytes long > 60=6The Address for FIELD2 is 000007 which means FIELD1 is 1 byte long > 76=1The Ending Address is 00000F which means FIELD2 is 8 byte long > F7=8 000000 D20010061007 MVC FIELD2,FIELD1 000006 FIELD1 DC CL1'? 000007 FIELD2 DS CL8 00000F ENDHow does the MVC instruction know where Field1 & 2 are?

John Urrutia 2012, All Rights Reserved.165/27/2012The Assembly ProcessIf we look at how the MVC instruction is composed:An OpCode which is always 1 byteA length values which is always 1 byteOperand 1 which is always 2 bytesOperand 2 which is always 2 bytesD20010061007For the operands we use an addressing scheme called Base & DisplacementThe first nibble represents an addressing or base register and the last 3 represent the displacement from that base.

John Urrutia 2012, All Rights Reserved.175/27/2012The Assembly ProcessHow does Base & Displacement work?Think of an addressing register as the address of a Local Post OfficeThink of displacement as one of the houses the Post Office delivers toBy using this we no longer have to store the full 3 byte address for each of the operands D200DEF006DEF007We store only the base register & displacement thereby saving 2 bytesRegister1 = DEF000 D20010061007

John Urrutia 2012, All Rights Reserved.185/27/2012The Assembly ProcessHow does Base & Displacement work?Since we use only 1 hexadecimal digit for the register it implies we have 16 to choose from at any one time0 thru FSince we use only 3 hexadecimal digit for the displacement it implies we have 4096 locations to choose from at any one time0 thru FFF

John Urrutia 2012, All Rights Reserved.195/27/2012The Assembly ProcessSo Given the following:Register1 = 00B000Displacement = EEFOne could say: Wheres the ---?00BEEF

John Urrutia 2012, All Rights Reserved.205/27/2012Assembler ElementsWhen you are assembling a program the Assembler must keep track of which storage addresses have already been used. This is done with the Assemblers Location Counter and always points to the next available byte and is displayed as a hexadecimal value on the left-hand side of the Assembler listing.Instructions come in 3 basic formats but have many variations.RR Register to RegisterRS Register to StorageSS Storage to Storage John Urrutia 2012, All Rights Reserved.215/27/2012Assembler ElementsThe 3 basic formats occupy 3 different lengths in storage.2 Byte instructionsRR Register to Register4 Byte instructionsRS Register to StorageRX Register to Indexed StorageSI Storage Immediate 6 Byte instructionsSS Storage to Storage John Urrutia 2012, All Rights Reserved.225/27/2012Assembler Elements2 Byte instructionsRR Register to Register

John Urrutia 2012, All Rights Reserved.235/27/2012

Assembler Elements4 Byte instructionsRS Register to StorageRX Register to Indexed StorageSI Storage Immediate

John Urrutia 2012, All Rights Reserved.245/27/2012

Assembler Elements6 Byte instructionsSS1 Storage to Storage (Decimal Operations)SS2 Storage to Storage

John Urrutia 2012, All Rights Reserved.255/27/2012

Assembler Elementsz390 Assembler ListingStart-up Messages John Urrutia 2012, All Rights Reserved.265/27/201216:22 AsmLstng MZ390 START USING z390 V1.5.05 ON J2SE 1.6.0_33 7/2/12AZ390I Copyright 2011 Automated Software Tools CorporationAZ390I z390 is licensed under GNU General Public LicenseAZ390I program = H:\Assembly Files\Ch10ASML\AsmLstngAZ390I options = sysmac(C:\PROGRA~2\AUTOMA~1\z390\mac+.) syscpy(C:\PROGRA~2\AUTOMA~1\z390\mac+.)Assembler Elementsz390 Assembler ListingProgram Listing John Urrutia 2012, All Rights Reserved.275/27/2012External Symbol Definitions ESD=0001 LOC=00000000 LEN=00000018 TYPE=CST NAME=$PRIVATEAssembler Listing000000 (1/1)1 USING *,15LISTUSE $PRIVATE ESD=0001 LOC=00000000 LEN=01000 REG=F OFF=00000 LAB=000000 D200F008F009 000008 000009 (1/2)2 MVC FIELD1,FIELD2000006 07FE (1/3)3 BR 14000008 6F (1/4)4 FIELD1 DC CL1'?'000009 (1/5)5 FIELD2 DS CL8000011 (1/6)6 ENDAssembler Elementsz390 Assembler ListingSymbol Definition and Cross Reference Listing John Urrutia 2012, All Rights Reserved.285/27/2012Symbol Table Listing

SYM=$PRIVATE LOC=00000000 LEN=00000018 ESD=0001 TYPE=CST XREF=1 SYM=FIELD1 LOC=00000008 LEN=00000001 ESD=0001 TYPE=REL XREF=4 2 SYM=FIELD2 LOC=00000009 LEN=00000008 ESD=0001 TYPE=REL XREF=5 2 Assembler Elementsz390 Assembler ListingShutdown Messages John Urrutia 2012, All Rights Reserved.295/27/2012AZ390I total mnote warnings = 0AZ390I total mnote errors = 0AZ390I max mnote level = 0AZ390I total mz390 errors = 0AZ390I total az390 errors = 016:22:54 AsmLstng MZ390 ENDED RC= 0 SEC= 0 MEM(MB)= 42 IO=37Assembler Elementsz390 Assembler ListingError Listing John Urrutia 2012, All Rights Reserved.305/27/201216:22:54 AsmLstng MZ390 START USING z390 V1.5.05 ON J2SE 1.6.0_33 07/0216:22:54 AsmLstng MZ390 ENDED RC= 0 SEC= 0 MEM(MB)= 42 IO=4116:22:54 AsmLstng LZ390 START USING z390 V1.5.05 ON J2SE 1.6.0_33 07/0216:22:54 AsmLstng LZ390 ENDED RC= 0 SEC= 0 MEM(MB)= 15 IO=2316:22:54 AsmLstng EZ390 START USING z390 V1.5.05 ON J2SE 1.6.0_33 07/0216:22:55 AsmLstng EZ390 ENDED RC= 0 SEC= 0 MEM(MB)= 20 IO=20 INS=3Assembler Elementsz390 Assembler ListingExecution Log John Urrutia 2012, All Rights Reserved.315/27/201216:22:54 AsmLstng EZ390 START USING z390 V1.5 ON J2SE 1.6.0_33 07/02EZ390I Copyright 2011 Automated Software Tools CorporationEZ390I z390 is licensed under GNU General Public LicenseEZ390I program = H:\CIS 20-AssemblyProgramming\Ch10ASML\AsmLstng.390EZ390I options = EZ390I instructions/sec = 176EZ390I total errors = 016:22:55 AsmLstng EZ390 ENDED RC= 0 SEC= 0 MEM(MB)= 20 IO=20 INS=3Debugging Guide - 3 levels of hellLevel 1 Assembler ErrorsSyntax Errors failure to follow directions.No error is acceptable in the assembly language!Non-correctable Syntax ErrorsOne simple error can generate many errors as a resultStart with the first error in the listing, correct it. Look for similar errors and correct all of them. Assemble again and repeat as needed.If you have done your job, you should be able to get a clean Assembly in 3 or less tries.

John Urrutia 2012, All Rights Reserved.325/27/2012Debugging Guide - 3 levels of hellLevel 1 Assembler ErrorsCorrectable Syntax ErrorsSome errors will stop the assembly process others will not but will result in errors further down the line that are much more difficult to identify.If an error exists but the assembler can correct it with a default value it will. (This is sloppy/lazy coding)Always check the .ERR file for RC = 0Any value other than 0 is not acceptable John Urrutia 2012, All Rights Reserved.335/27/2012Debugging Guide - 3 levels of hellLevel 2 Assembler Coding ErrorsThese are the errors the assembler will not catch. They will show up when you run your program.These errors could be considered logic errors but not in the sense of processing.Whats wrong here?

John Urrutia 2012, All Rights Reserved.345/27/2012

Debugging Guide - 3 levels of hellLevel 2 Assembler Coding ErrorsWhats wrong here?

John Urrutia 2012, All Rights Reserved.355/27/2012

Debugging Guide - 3 levels of hellLevel 3 Logic ErrorsThese are errors of omissionDidnt know the domain was larger or smallerDidnt know the input data were characters not numbersFailed to calculate the correct field sizeLost addressabilityCoded wrong instructionDivided by zeroBoth Level 2 & 3 usually result in an ABENDABnormal END to program execution is a good bad thingExecution to normal end with invalid output is a really bad thing!! John Urrutia 2012, All Rights Reserved.365/27/2012Debugging Guide - 3 levels of hellWhat happens when you ABENDSystem detects an error and issues a system exception using a Program Interruption Code. John Urrutia 2012, All Rights Reserved.375/27/2012

Debugging Guide - 3 levels of hellWhat happens when you ABENDSystem terminates the program, restores system integrity and continues to process other tasks.If requested the system will produce a DUMP, that is a report, which is a hexadecimal image of the program that had the problem. The ABEND can be used to identify what was happening at the time. John Urrutia 2012, All Rights Reserved.385/27/2012Debugging Guide - 3 levels of hellThe ERR file15:57:05 ABENDLst EZ390 START USING z390 V1.5.05 ON J2SE 1.6.0 07/0315:57:05 ABENDLst EZ390 EZ390E error 11 ABEND PSW=07050600 800FFFDA FA07D072D073 AP ABEND S0C715:57:06 ABENDLst EZ390 EZ390E error 12 program aborting due to S0C715:57:06 ABENDLst EZ390 ENDED RC=16 SEC= 0 MEM(MB)= 21 IO=90 INS=6

The PSW tells us what instruction is about to execute and the current instruction that failed follows along with the ABEND code. John Urrutia 2012, All Rights Reserved.395/27/2012Debugging Guide - 3 levels of hellThe LOG and PRN files The system LOG file contains the DUMPThe system PRN file is the assembly listing of the program.ExerciseIdentify the registersIdentify the programIdentify the instruction John Urrutia 2012, All Rights Reserved.405/27/2012ASM Code Sheet LABEL1OPERATION10 OPERANDS COMMENTS1672

Name ___________________________________________________CIS 020 Assembly Programming

Sheet2LABELOPERATIONOPERANDS11116I1MVCOUT,PAT1I2EDOUT,DATA1

OUTDSCL9PATDSX'40212020'DATADSPL3'1000'

BEFOREAFTERI1OUTX'??????????'OUTX'40216B2020204B2020'PATX'40216B2020204B2020'PATX'40216B2020204B2020'I2OUTX'40216B2020204B2020'OUT X'40F16BF0F0F04BF0F0'DATAX'01000F'DATAX'01000F'

Name ___________________________________________________CIS 020 Assembly Programming

ASM Code Sheet LABEL1OPERATION10 OPERANDS COMMENTS1672

Name ___________________________________________________CIS 020 Assembly Programming

Sheet2LABELOPERATIONOPERANDS11116I1MVCOUT,CLEARI2APDATA,DATA

OUTDC0CL10CLEARDCC'O'DATADCPL3'1000'

BEFOREAFTERI1OUTX'??????????'OUTX'40216B2020204B2020'PATX'40216B2020204B2020'PATX'40216B2020204B2020'I2OUTX'40216B2020204B2020'OUT X'40F16BF0F0F04BF0F0'DATAX'01000F'DATAX'01000F'

Name ___________________________________________________CIS 020 Assembly Programming

ASM Code Sheet LABEL1OPERATION10 OPERANDS COMMENTS1672

Name ___________________________________________________CIS 020 Assembly Programming

Sheet2LABELOPERATIONOPERANDS11116I1MVCOUT,CLEARI2APDATA,DATAI3OUTDC0CL10CLEARDCC'O'DATADCPL3'1000'

BEFOREAFTERI1OUTX'??????????'OUTX'40216B2020204B2020'PATX'40216B2020204B2020'PATX'40216B2020204B2020'I2OUTX'40216B2020204B2020'OUT X'40F16BF0F0F04BF0F0'DATAX'01000F'DATAX'01000F'

Name ___________________________________________________CIS 020 Assembly Programming

Sheet1Program InterruptCodeOperation0001Privileged operation0002Execute0003Protection0004Addressing0005Specification0006Data0007Fixed-point overflow0008Fixed-point divide0009Decimal overflow000ADecimal divide000BHFP exp. overflow000CHFP exp. underflow000D

ASM Code Sheet LABEL1OPERATION10 OPERANDS COMMENTS1672

Name ___________________________________________________CIS 020 Assembly Programming

Sheet2LABELOPERATIONOPERANDS11116I1MVCOUT,CLEARI2APDATA,DATAI3OUTDC0CL10CLEARDCC'O'DATADCPL3'1000'

BEFOREAFTERI1OUTX'??????????'OUTX'40216B2020204B2020'PATX'40216B2020204B2020'PATX'40216B2020204B2020'I2OUTX'40216B2020204B2020'OUT X'40F16BF0F0F04BF0F0'DATAX'01000F'DATAX'01000F'

Name ___________________________________________________CIS 020 Assembly Programming

Sheet1Program InterruptCodeOperation0001Privileged operation0002Execute0003Protection0004Addressing0005Specification0006Data0007Fixed-point overflow0008Fixed-point divide0009Decimal overflow000ADecimal divide000BHFP exp. overflow000CHFP exp. underflow000D