Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lab 5 Part C Write to the screen a character string that uses a ‘$’ to indicate the end of the string. Do not write the ‘$’ to the screen. Use DOS Interrupt.

Similar presentations


Presentation on theme: "Lab 5 Part C Write to the screen a character string that uses a ‘$’ to indicate the end of the string. Do not write the ‘$’ to the screen. Use DOS Interrupt."— Presentation transcript:

1 Lab 5 Part C Write to the screen a character string that uses a ‘$’ to indicate the end of the string. Do not write the ‘$’ to the screen. Use DOS Interrupt 21h Function 2 to write each character of the string to the screen.

2 How to Compare Want to compare each character in the string to ‘$’ character. –If not equal, write character –Else, exit program Alternatively, –If equal, exit program –Else, write character

3 Moving Through a String of Characters Use a pointer register to point to the beginning of the string. (SI) Loop through the string one character at a time. (INC SI)

4 Writing a String to the Screen Move value pointed to into register DL Is Equal to ‘$’’ Write character on screen NO Exit Program YES S Increment pointer register SI Move beginning of string into pointer register SI

5 Instructions for Writing to Screen Exiting Program Writing to the screen using Interrupt 21h (the character to be written must be stored in DL) Mov ah, 2;put function number in ah Int 21h;call interrupt 21h Exiting program Mov ah, 4Ch;put function number in ah Int 21h;call interrupt 21h

6 Compare Loop MOV SI, OFFSET string1 LP1: MOVDL, [SI];Note DL CMP DL, ‘$’ JE Exit …….;print here INCSI JMPLP1

7 Put code inside template.code Main proc movax, @data;initialize data segment movds, ax movSI, offset string1;SI is pointer to string1 LP1: movdl, [SI];save char in dl cmp dl, ‘$’;compare char to ‘$’ jeexit incSI;point to next char movah, 2;print char int 21h jmpLP1;end of loop EXIT:movah, 4Ch;exit program int21h Mainendp END Main

8 Writing a Character String in UpperCase, LowerCase or Reversing Case OR each Character with 20h creates uppercase characters AND each character with DFh creates Lowercase characters XOR each character with 20h reverses the case. Uppercase becomes lowercase; Lowercase becomes uppercase

9 Lab 5 Part D Write to the screen an 8-bit number that is stored in memory. Write the number in binary. Write each binary bit as a character using DOS Interrupt 21h, function 2.

10 Dealing with Bits To look at each bit, we need to use instructions that deal with bits. The shift and rotate instructions allow us to evaluate individual bits. shr bl, 1 the lsb is placed in the carry flag shl bl, 1 The msb is placed in the carry flag

11 Jumps Based on Status A conditional jump based on the value of the carry status flag would then be taken

12 What is a 1 and 0 in ASCII 0 = 30h 1 = 31h Therefore, move dl, 30h if carry flag = 0 Move dl, 31h if carry flag = 1

13 Pseudocode Move number into register from memory Setup loop = 8 to access each bit individually LP1:Shift each bit into carry flag Jump to Is_One procedure if carry = 1 Else move into DL, 30h Jump to print label Is_One: Move into DL, 31h Print: Use DOS interrupt Function 2 to write char to screen. Loop back to LP1 if CX >= 0 Exit

14 Writing a Number in Binary Shift BL by one to get msb into carry flag Carry Equals 1? Move 30h into DL NO NO Mov 31h into DL YES S Write character on screen Move 8 into CX (dealing with a byte value) Move Number into BL

15 Lab 6 Part A Write a number in hexadecimal. Use DOS interrupt 21h, function 2 to write a character to the screen. Write a CRLF procedure since this function is used so often. Use the DOS interrupt 21h, function 2 to write the appropriate characters to generate a CR and LF on the screen.

16 Converting a Decimal Digit to a Hex Digit You know how to change a bit that represents a decimal value 0-1 to an ASCII character value. Add 30h to the value. Use 4 bits to represent the decimal values 0-9. Compare the value to see if the value is greater than 9. If so, it must be a character A-F.

17 How do You only look at 4 bits out of a Byte Size Register? MASK the upper four bits of the byte. Be sure to save the value of the byte before you mask it; the register will get changed. Use AND 0Fh to keep the lower four bits; hide the upper four bits of the 8 bit register value. You now have a value between 0 and 15. Compare to 9 –Equal or less – no change (add 30h to get ASCII value) –Greater => must be a character. (add 37h to get ASCII value)

18 Convert_to_Hex Procedure (Changes the value of AL) Convert_to_Hexproc And al, 0Fh Cmp al, 9 Ja ischar Add al, 30h jmp exit Ischar:Add al, 37h Exit:ret Convert_to_Hexproc

19 How do you write a Carriage Return to the screen There is an ASCII character labelled “Carriage Return” (0Dh) There is an ASCII character labelled “Line Feed” (0Ah)

20 PCRLF Procedure Pcrlf Proc mov ah, 2 mov dl, 0Ah int 21h mov dl, 0Dh int 21h ret

21 Print_char Procedure Print_charproc movah, 2 int21h ret Print_charendp

22 Main Program Mainproc movax, @data mov ds, ax pushax call convert_to_hex movdl, al call print_char call pcrlf movax, 4c00h int 21h Mainendp

23 Order of Procedures Mainproc ….. Mainendp Convert_to_Hexproc ….. Convert_to_Hexendp Print_charproc ….. Print_charendp Pcrlfproc ….. Pcrlfendp End Main

24 ASCII Decimal String to Hex Conversion Given a two digit unsigned decimal string, with each digit in ASCII, convert it to the correct 8-bit value.

25 Conversion from ASCII The first ASCII value is the 10’s digit. Subtract 30h from the value to get the unsigned binary (or hex) representation, then multiply it by 10. Subtract 30h from the second digit, and then add it to the result of the first operation.


Download ppt "Lab 5 Part C Write to the screen a character string that uses a ‘$’ to indicate the end of the string. Do not write the ‘$’ to the screen. Use DOS Interrupt."

Similar presentations


Ads by Google