NOVA CSC 206 - Numeric Conversions and Libraries

Unformatted text preview:

Chapter 9 Numeric Conversions and LibrariesTopicsCharacter Translation MethodsCharacter Translation Methods ContinuedCharacter Translation MethodsCharacter EncodingStack ParametersStack Parameters ContinuedSlide 9Passing Parameters by ReferencePassing Parameters by Reference ContinuedSlide 12Slide 13Slide 14Slide 15Loading Segment AddressSlide 17Loading Segment Address ContinuedThe Enter InstructionThe Leave InstructionExample using the ENTER and LEAVE instructionsPassing Parameters using the C Calling ConventionProcedure Declaration In Microsoft MASMProcedure Declaration In Microsoft MASM ContinuedSlide 25Slide 26Slide 27Procedure Declaration In Microsoft MASM ContinuedSeparately Assembled ModulesSlide 30Separately Assembled Modules ContinuedSlide 32Slide 33Slide 34Separately Assembled Modules ContinuedSeparately Assembled Modules ContinuedSlide 37Slide 38Binary to ASCII ConversionCSC 20601/13/19 1Chapter 9 Numeric Conversions and LibrariesInstructor: James Hutchinson 1 1 3 CSC 20601/13/19 2TopicsCharacter Translation MethodsStack ParametersSeparately Assembled ModulesCreating a Link LibraryBinary to ASCII ConversionASCII to Binary ConversionCSC 20601/13/19 3Character Translation MethodsIntroduction: Character translation is the process of converting character symbols to the value they represent.The XLAT Instruction.Definition: The XLAT instruction adds the contents of AL to BX and uses the resulting value as an offset pointer to a location in a translation array of byte size elements.General Form. XLATWhere BX contains the offset address of a translation array. AL contains the 8-bit character to be translated.Example: Consider the requirement to convert a sequence of hex digit to their ASCII representation .Table db ‘0123456789ABCDEF’MOV BX, Offset TableMOV AL, 0BhXLATCSC 20601/13/19 4Character Translation MethodsContinuedCharacter Filtering.Definition: The process of eliminating character elements based on their ASCII value.Example, Write a program to remove all none alphabetic characters from an input array..model flat.stack 100h.datainputData db ‘now 2& tune’Validchars Label bytedb 65 dup(0) db 26 dup(1) ; the upper case letters db 6 dup(0) db 26 dup(1) ; the lower case lettersCSC 20601/13/19 5Character Translation Methods.CODEMain ProcMOV ECX, 11MOV EBX, Offset ValidCharsMOV EDI, Offset inputDatagetchar:MOV AL, [EDI]XLAT CMP AL,1 JE ContinueMOV [EDI], ‘ ‘Continue:INC EDILoop getcharMain endpEND MainCSC 20601/13/19 6Character EncodingThe XLAT instruction provides a simple means for encrypting data for electronic transmission.A Translation table is use to convert readable characters to its encrypted form.Example:CodeTable db ‘8409320-=+ aldlk…. all ASCII characters’Each readable character will be used to find its encrypted representation.CSC 20601/13/19 7Stack ParametersThe most common method for passing parameters to a function is through the use of the stack.The calling module can push each parameter on the stack just before calling a procedure (Proc in Assembler)The called procedure can retrieve the values from the stack.This method of passing parameters supports both pass by reference and pass by value methods.Most high-level language use this method.The order operation when a function or procedure is calledFor a near call the IP is pushed onto the stackA Far call requires both the IP and CS registers be pushed onto the stack.When parameters are passed on the stack:Parameters return address (IP or IP CS)CSC 20601/13/19 8Stack Parameters ContinuedExample:mov ax, 25push axmov ax, offset var1push axcall procAxor cx, cxadd cx, 35procA Procpush spmov bp, spmov dx, [bp+6] ;pass by value parametermov si, [bp+4] ;pass by reference paramterStackBP + 6BP + 4BP + 2BP, SP20019819619419219025 ADDR VAR1RTRN ADDRBPCSC 20601/13/19 9Stack Parameters ContinuedStack Cleanup.Parameters passed on the stack cannot be left on the stack. They would cause a problem when procedure returns to the calling module.One way to handle this problem is to add a constant number to the ret instruction .Example: ret n where n is a positive integer that indicates the number of bytes to skip when returning to the calling module.To cleanup the stack after the call to the previous example, the return instruction would be coded ret 4.Another method is to leave stack cleanup to the calling module.CSC 20601/13/19 10Passing Parameters by ReferenceWhen a parameter is passed by reference, the address of parameter is passed to the called procedure.The called procedure has update access to the parameter.Any modifications made to the parameter during the procedure call impacts the parameter in the calling module.Example:Write a procedure to initialize an array of characters to all blanks given the length of the array. To solve this problem, all parameters will be passed using the stack..dataline db 80 dup(?)lineLength = 80CSC 20601/13/19 11Passing Parameters by ReferenceContinuedInitialize Procpush bp ; save bp registermov bp,sp ; initialize bp to the correct location in the stackpusha ; save all registersmov si, [bp+4] ; get the address of line off the stackmov cx, [bp+2] ; get the length of the string.Doagain:mov byte ptr [si], ‘ ‘ ; store a blank in the stringinc si ; point to the next location in the stringloop Doagainpopa ; restore all registerspop bpret 4 ; delete 4 bytes off of the stackInitialize EndpCSC 20601/13/19 12Passing Parameters by ReferenceContinued.CodeMain Proc Farmov ax,@data ; establish addressabilitymov ds, ax ; initialize the ds register mov ax, lineLength ; get the length of a linepush ax ; store the line length on the stackmov ax, offset line ; get the address of line push ax ; store the address on the stackcall Initializemov ax, 4c00h ; terminate programint 21h Main endpCSC 20601/13/19 13Passing Parameters by ReferenceContinuedPassing Far Pointers.There are times when a variable must be passed by reference to a procedure whose data is stored in a different segment from the calling module.For example, passing parameters in a large or flat model.When passing a far pointer, the calling module must pass both the segment and the offset address of the parameter to the called module:.model Large.stack 100h.dataline db 80 dup(?)lineLength = 80CSC 20601/13/19


View Full Document

NOVA CSC 206 - Numeric Conversions and Libraries

Download Numeric Conversions and Libraries
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Numeric Conversions and Libraries and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Numeric Conversions and Libraries 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?