Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement: Add support for 16bit constant from two ascii chars #199

Open
wants to merge 1 commit into
base: master_archived
Choose a base branch
from

Conversation

furious
Copy link

@furious furious commented Feb 17, 2021

Minor changes to add support for 16bit values made of two chars, eg.: lda.w #'AS' : sta $00 : lda.w #'AR' : sta $02

@coveralls
Copy link

coveralls commented Feb 17, 2021

Coverage Status

Coverage decreased (-0.05%) to 81.805% when pulling fec2161 on furious:feature/16bit-ascii-chars into 99d1b72 on RPGHacker:master.

@Alcaro
Copy link
Contributor

Alcaro commented Feb 17, 2021

'a' = $1234
'b' = $5678
dw 'a','b'

yields, with the current Asar, 34 12 78 56.

What do you propose would be the correct output for the following snippets, and is that the actual output of this PR?

'a' = $1234
'b' = $5678
dw 'ab'
'a' = $12
'b' = $34
'c' = $56
dl 'abc'

@furious
Copy link
Author

furious commented Feb 17, 2021

The purpose is just for opcodes, not to change ascii table. I was disassembling a firmware that checks strings in specific locations, eg.:

; checking for "SUPERUFO" at 808000
org $808000:
    db "SUPERUFO"
...
    lda.l $808000
    cmp.w #$5355 ; when loading as 16 bit, it flip bytes to 'US' instead of the actual readable text 'SU'
    bne .not_superufo
    lda.l $808002
    cmp.w #$5045 ; 'EP' > 'PE'
    bne .not_superufo
    lda.l $808004
    cmp.w #$5255 ; 'UR' > 'RU'
    bne .not_superufo
    lda.l $808006
    cmp.w #$464F ; 'OF' > 'FO'
    bne .not_superufo

Currently, Asar only supports single char constant conversion lda.b #'A'. My intention of this PR is to make it also support 16 bit constants made from chars/text...

I was manually writing the opcode with the inverse char order, eg.:

db $C9, "US" ; = cmp.w #$5355

@furious furious force-pushed the feature/16bit-ascii-chars branch from 6babd4e to fec2161 Compare March 1, 2021 03:35
@furious
Copy link
Author

furious commented Mar 1, 2021

Sorry, I was wrong, that piece of code I showed was written with the bytes actually flipped, so I just pushed a correction...

Here's a real example of this feature:
image
In this code, it checks for a specific header string above
image

@p4plus2
Copy link
Collaborator

p4plus2 commented Mar 9, 2021

I don't really know how I feel about this one. Maybe this is better as a builtin function (say be for big endian) so it can be used in any math context. be($1234) or be("US") could then be supported for example.

I'm open to other suggestions too, but I'd rather not add a context sensitive hack. A be function could hypothetically support strings larger too, up to four bytes. Thus would work with d[bwld] (though db its effectively a noop)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants