Lecture37W_F

Lecture37W_F - Multiprecision Arithmetic Arithmetic on...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Multiprecision Arithmetic Arithmetic on numbers larger than data format · BCD numbers larger than 2 digits (1 byte) · Standard binary numbers larger than register (16 bits = 2 bytes) BCD · As observed in Lab Exercise 6, BCD instructions use carry (“C”) bit as well as half (“H”) bit. · C bit of CCR - Carry for addition - Borrow for subtraction · Example: Subroutine to add 2 BCD strings of 16 BCD digits: String1 = String1 + String2 BCD_BYTES: EQU 8 ; # bytes for 16 BCD digits AddBCD: ldab #BCD_BYTES ;Loop counter ldx #(String1+BCD_BYTES) ;String1 ptr ldy #(String2+BCD_BYTES) ;String2 ptr clc ;clear C bit if CCR Loop: ;repeat { ldaa 1,-x ; adca 1,-y ; daa A = byte of String1 + byte of String2 ; Adjust A for BCD add Store in String1 staa 0,x ; dbne b,Loop ;} until (--B == 0) rts MyData: SECTION String1: DS.B BCD_BYTES String2: DS.B BCD_BYTES Page 1 of 2 Multiprecision Arithmetic Page 2 of 2 Standard binary numbers · HCS instructions for arithmetic with carry (C bit) - ADCA (M)—byte ADCB (M)—byte - · · A ß A + (M) + C SBCA (M)—byte · A ß A - (M) - C · B ß B + (M) + C SBCB (M)—byte · B ß B - (M) - C Example: Subroutine to add two 64-bit numbers: Num1 = Num1 + Num2 NUM_BYTES: EQU 8 ; # bytes in 64-bit number Add64: ldab #NUM_BYTES ;loop counter ldx #(Num1+NUM_BYTES) ;Ptr. to Num1 ldy #(Num2+NUM_BYTES) ;Ptr. to Num2 clc ;Clear C bit of CCR Loop: ;repeat { ldaa 1,-x ; adca 1,-y ; + byte of Num2 staa 0,x ; Num1 = Num1 + Num2 dbne b,Loop ;} until (--B == 0) rts MyData: SECTION Num1: DS.B NUM_BYTES Num2: DS.B NUM_BYTES A = byte of Num1 ...
View Full Document

Ask a homework question - tutors are online