Between 3a and 40 is error cmp al 46h assembly

This preview shows page 12 - 16 out of 22 pages.

; Between 3A and 40 is error
Image of page 12

Subscribe to view the full document.

CMP AL, 46h Assembly Language Programming (Parl-I) J A. ERROR ; Out of ASCII 0-9, A-F range SUB AL, 37h ; It's a letter so convert JMP CONVERTED NUMBER: SUB AL, 30h ; It's a number so convert JMP CONVERTED ERROR: MOV AL,OFFh CONVERTED: NOP ; The hex result is in AL CODE ENDS END START In the above program, we have demonstrated it for a single binary digit represented by and ASCII character. The program can be extended to take more ASCII digirs .tnd convert them into a 16 t i t hinarv numhcr. Thi5 can hc done in rhc follouing m'rnncr: Example: Assume CX contains the hexadecimal number obtained afrer conversion. BX contains 10, AX contains the number obtained till now. To start with AX was equal to 0. Now assume that AX has become 0020h and CL = 02. AND CX, OOOFh ; convert digit to binary MUL BX ; DX :AX = AX * 10 ADD AX,CX ; add new digit to AX Follow the above steps with the AX and CL values given above. AL is multiplied by BL, so AX = 0140h. CL is added to AX, yielding 142h. You can improve your program by checking for overflow conditions also. Check Your Progress 2 1 Write the code sequence in assembly for performing following operation: Z = ((A-B) / 10 * C) ** 2 ................................................................... 2 . Write an assembly code sequence for adding an array of binary numbers. 3. An assembly program is to be written for inputting two 4 digits decimal numbers from console, adding them up and putting back the results. Will you prefer packed BCD addi~ion for such numbers? Why?
Image of page 13
................................................................... Microprocessor and Assembly Language Programming ................................................................... How can we implement nested loops, for example, for (i = 1 to 10, step 1) { for (j = 1 to 10, step 1) addltoax) in assembly language? .................................................................... 3.4 PROGRAMMING FOR ARITHMETIC AND STRJNG OPERATIONS In this section we go a step forward, to look at more advanced features of assembly language programming. These are some of the features that give it an edge over the high level language programming. One of the very important set of instructions is for string processing. If you write the same code in high level language, the object code generated after compiling is much longer than for the same program written in assembly language. In the next section we shall demonstrate this. 3.4.1 String Processing Write a program in any high level language for comparing two strings. Consider the following piece of code which has been written in some hypothetical high level language, to compare two strings. Let us assume that 'strl' and 'strZ are two strings, initialized by some values, and 'in& is the index for these character strings. Consider the following program: while (ind < 9) and (strl[ind] = str2[ind]) do ind : = ind + 1; The intermediate code in assembly language generated by the compiler for the above piece would look something like this: MOV IND,00 ; ind : = 0 L3: CMP IND, 08 ; ind < 9 JG L1 ; not so; skip LEA AX,STRl ; offset of strl in AX register MOV BX,IND LEA CX,STR2 ; it uses a register for indexing intothe array ; str2 in CX
Image of page 14

Subscribe to view the full document.

MOV DL, BYTE PTR CX[BX] CMP DL, BYTE PTR AX[BX] ; strl[ind] = str2[ind] JNE L1 ; no, skip MOV IND,BX ADD IND,01 L2: JMP L3 ; loop back You see, there is lot of redundant code, which could have been avoided, if we had written the same program directly in assembly language. The code
Image of page 15
Image of page 16
You've reached the end of this preview.
  • Spring '10
  • Ramon
  • Assembly Language, X86, Binary numeral system, ........., Binary-coded decimal, ax

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern