Download presentation
Presentation is loading. Please wait.
Published byBeatrix Burke Modified over 6 years ago
1
e. g. Write a program to count the spaces in a string
e.g. Write a program to count the spaces in a string. The end of the string is indicated by a carriage return, $0D. input: string DC.B “some stuff”,$0D output: num_sp [Matthew Bamberg, Aug 2012]
2
e. g. Write a program to count the spaces in a string
e.g. Write a program to count the spaces in a string. The end of the string is indicated by a carriage return, $0D. What happens if there is no carriage return?
3
Looping Structure … DBcc
a decrement and branch instruction handles two concurrent conditions one conditional test one loop count DBcc Dn,<label> Bcc conditions plus: DBT DBF DBRA
4
Looping Structure … DBcc
DBcc Dn,<label> if the condition being tested is satisfied, control passes to the instruction after the DBcc if the condition is not satisfied, then lower 16 bits of Dn is decremented by one if the result is -1, control passes to the instruction following the DBcc otherwise, control transferred to <label>
5
==> variation 1 e.g. Write a program to determine the length of a string of characters. NOT preferred style! LEA str,A0 ; point to string MOVEQ #0,D0 ; clear str length MOVE.W #99,D2 ; string max = 100 chars loop CMPI.B #$0D,(A0)+ ; carriage return or DBEQ D2,incr ; max string length? MOVE.W D0,str_l ; yes, save length BRA done ; and exit incr ADDQ.W #1,D0 ; no, increment len cnt BRA loop ; and check next char done … … STOP $#2700 str DC.B 'Hi!',$0D str_l DS.W 1
6
==> variation 2 e.g. Write a program to determine the length of a string of characters. LEA str,A0 ;point to string MOVEQ.W #-1,D0 ;initialize length cnt MOVE.W #99,D2 ; and string max = 100 loop ADDQ.W #1,D0 ;increment length count CMPI.B #$0D,(A0)+ ;carriage return or DBEQ D2,loop ; max str len? no,loop MOVE.W D0,str_l ;yes, save length … STOP #$2700 str DC.B 'Hi!',$0D str_l DS.W 1
7
==> variation 3 e.g. Write a program to determine the length of a string of characters. LEA str,A0 ;point to string MOVE.W #99,D2 ;initialize str max=100 MOVE.W D2,D0 ; and length loop CMPI.B #$0D,(A0)+ ;<cr> or max str len? DBEQ D0,loop ; no, loop SUB.W D0,D2 ; yes, calc str length MOVE.W D2,str_l ; and store … STOP #$2700 str DC.B 'Hi!',$0D str_l DS.W 1
8
IEEE Standard for Floating Point Arithmetic
Number (single precision) is stored as S EEEEEEEE FFFFFFFFFFFFFFFFFFFFFFF Fraction: sign magnitude normalized by minimizing the number of leading zeros to improve accuracy uses hidden bit to squeeze out one more digit of accuracy e.g x 24 normalized = 0.12 x with hidden bit = 1.02 x 21
9
IEEE Standard for Floating Point Arithmetic
Exponent: 2’s complement with bias of 127 or exponent = exponent value e.g x 24 normalized with hidden bit = 1.02 x 21 fraction = exponent = = Number (single precision) is stored as S EEEEEEEE FFFFFFFFFFFFFFFFFFFFFFF =
10
e.g. normalize a 32 bit binary number
Normalization: shift a 32 bit number until the most significant bit of the number is 1 store the normalized number store the number of left shifts e.g … =
11
e.g. normalize a 32 bit binary number
12
e.g. normalize a 32 bit binary number
13
Reading & Expectations
M68000 Assembly Language [pdf; 92p; N. Znotinas] operation of DBcc instruction For interest only: IEEE Standard for Floating-Point Arithmetic [pdf; 58p; IEEE Computer Society, IEEE Std 754; August 2008] IEEE Arithmetic [© 2000 Sun Microsystems, Inc.] Expectations: you can use DBcc correctly and to your advantage you could rewrite most of our existing looping programs using DBcc (but it may not be helpful in all instances)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.