IGNORED

# Inverting Values

## Recommended Posts

In Odyssey 2 and Channel F assembly, there is a function which inverts the number, so like if it was, say, 167 and you call the function, the number would change to 88. I was just wondering if there is a way to do this in Atari 2600 assembly and if so, how?

##### Share on other sites

Well, invert would be EOR #\$FF, but 0xB0 (167) EOR 0xFF = 0x4F (79).

##### Share on other sites

I get 88.

By "invert", do you mean reverse the bits, or something else?

##### Share on other sites

1 hour ago, Karl G said:

I get 88.

Spoiler.

##### Share on other sites

Basically, what I need to do is get the number on the left column to get to the number on the right column (and the number on the right column to be the number on the left).

```
174 80
173 81
172 82
171 83
170 84
169 85
168 86
167 87
166 88
165 89
164 90
163 91
162 92
161 93
160 94
159 95
158 96
157 97
156 98
155 99
154 100
153 101
152 102
151 103
150 104
149 105
148 106
147 107
146 108
145 109
144 110
143 111
142 112
141 113
140 114
139 115
138 116
137 117
136 118
135 119
134 120
133 121
132 122
131 123
130 124
129 125
128 126
127 127

```

All I can tell from this is that if you add all the rows, they all equal 254.

```  sec
lda #254
sbc value
```

##### Share on other sites

```lda value
eor #\$ff
clc

##### Share on other sites

Thanks for the help, I really appreciate it. Seems like there's more than one way to do it.

##### Share on other sites

5 hours ago, Thomas Jentzsch said:
```
lda value
eor #\$ff
clc

That negates a value. That's not what was asked for.

The requirement is A+B = 254.  Given A, calculate B.
I don't think your example will give the results from the table shown.

• 1
• 1
##### Share on other sites

I believe what Thomas meant was:

```    eor    #\$FF
sec
sbc    #1```

That will fulfill the requirement is A+B = 254. Given A, calculate B. It saves a byte of ram and 1 cycle over subtracting using a ZP ram location.

In the rare case that X is preloaded with #\$FF there is an illegal optimization. The resulting 'B' value ends up in the X register:

```    eor    #\$FF
sbx    #1```

##### Share on other sites

9 hours ago, Andrew Davie said:

That negates a value. That's not what was asked for.

The requirement is A+B = 254.  Given A, calculate B.
I don't think your example will give the results from the table shown.

You are right.

##### Share on other sites

3 hours ago, Omegamatrix said:

I believe what Thomas meant was:

```
eor    #\$FF
sec
sbc    #1```

That will fulfill the requirement is A+B = 254. Given A, calculate B. It saves a byte of ram and 1 cycle over subtracting using a ZP ram location.

Well, assuming you have the value in the accumulator to start with. That's cheating

##### Share on other sites

13 hours ago, Andrew Davie said:

Well, assuming you have the value in the accumulator to start with. That's cheating

He he, your code assumed the value in a variable.

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.