Download Primer Self-Instruction Manual
Transcript
Load the above program into memory then load the DE register pair with 0080 hex (128 decimal) and run the program. This value is chosen because it will show that after you run the program, bit 7 of E is shifted into bit 0 of D, giving a result of 0100 (128 * 2 = 256 decimal). Examine the DE register pair to verify this. Run the program using other values for DE and verify that the program really does multiply DE by 2, but make sure values are less than 8000 hex or the result won't fit in the DE register pair. If you want to multiply the HL register pair by 2 the DAD H instruction can be used. It adds HL to HL which is the same as multiplying HL by 2. Below is a simple program which illustrates the DAD H instruction. loop: org 0ff01h dad h jmp loop ADDRESS FF01 FF02 FF03 FF04 ; add hl to hl ; do it again DATA 29 C3 01 FF INSTRUCTION DAD H JMP FF01 Load the program into memory and press reset then perform the same tests that were done for the previous example by loading the HL register pair with the same values that DE was loaded with and single stepping. The results will be the same. A quick "times 10" algorithm can be made using a combination of multiply by 2 instructions and an addition instruction. Below is the equation " X = Y * 10 " which is broken down into a form which the 8085 can easily handle: X X X X = = = = Y * 10 (Y * 5) * 2 ((Y * 4) + Y) * 2 ((Y * 2 * 2) + Y) * 2 The last equation above is translated into the following program. org mov mov dad dad dad dad rst end ADDRESS FF01 FF02 FF03 FF04 FF05 FF06 FF07 0ff01h d,h ; e,l ; h ; h ; d ; h ; 7 ; DATA 54 5D 29 29 19 29 FF put original value of HL into DE HL = HL * 2 HL = HL * 2 HL = HL + DE HL = HL * 2 return to MOS INSTRUCTION MOV D,H MOV E,L DAD H DAD H DAD D DAD H RST 7 Load the program into memory then load HL with 0003. After running the program, HL will be 001E which is 30 decimal. Change the program counter back to FF01 (don't press reset, or the registers will be cleared) then run the program again. This time HL will be 012C which is 300 decimal. In the lesson "Using Monitor Operating System Subroutines" is a description of a service which multiplies two 16 bit numbers. 41