Jump to content

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?

Link to comment
https://forums.atariage.com/topic/316989-inverting-values/
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.

Link to comment
https://forums.atariage.com/topic/316989-inverting-values/#findComment-4749367
Share on other sites

5 hours ago, Thomas Jentzsch said:

lda value
eor #$ff
clc
adc #1

 

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.

  • Like 1
  • Thanks 1
Link to comment
https://forums.atariage.com/topic/316989-inverting-values/#findComment-4749960
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

 

  • Thanks 1
Link to comment
https://forums.atariage.com/topic/316989-inverting-values/#findComment-4750230
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.

Link to comment
https://forums.atariage.com/topic/316989-inverting-values/#findComment-4750313
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 :P

 

  • Haha 1
Link to comment
https://forums.atariage.com/topic/316989-inverting-values/#findComment-4750320
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...