-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddressMode.go
54 lines (46 loc) · 1.34 KB
/
addressMode.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package dsp56k
import (
"errors"
"fmt"
"io"
)
type EffectiveAddress struct {
Mode AddressMode
AddressRegister uint32
}
func EA(mode AddressMode, reg uint32) EffectiveAddress {
return EffectiveAddress{mode, reg}
}
type AddressMode int
const (
AddressModeInvalid AddressMode = iota
AddressModePostDecrementOffset
AddressModePostIncrementOffset
AddressModePostDecrement
AddressModePostIncrement
AddressModeNoUpdate
AddressModeIndexed
AddressModePreDecrement
)
func (ea EffectiveAddress) WriteOperand(w io.Writer, opts Options, pc uint32) (int, error) {
if ea.AddressRegister > 7 {
return 0, errors.New("invalid address register")
}
switch ea.Mode {
case AddressModePostDecrementOffset:
return fmt.Fprintf(w, "(r%[1]d)-n%[1]d", ea.AddressRegister)
case AddressModePostIncrementOffset:
return fmt.Fprintf(w, "(r%[1]d)+n%[1]d", ea.AddressRegister)
case AddressModePostDecrement:
return fmt.Fprintf(w, "(r%d)-", ea.AddressRegister)
case AddressModePostIncrement:
return fmt.Fprintf(w, "(r%d)+", ea.AddressRegister)
case AddressModeNoUpdate:
return fmt.Fprintf(w, "(r%d)", ea.AddressRegister)
case AddressModeIndexed:
return fmt.Fprintf(w, "(r%[1]d+n%[1]d)", ea.AddressRegister)
case AddressModePreDecrement:
return fmt.Fprintf(w, "-(r%d)", ea.AddressRegister)
}
return 0, errors.New("invalid effective address mode")
}