asar icon indicating copy to clipboard operation
asar copied to clipboard

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

Open furious opened this issue 4 years ago • 5 comments

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

furious avatar Feb 17 '21 15:02 furious

Coverage Status

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

coveralls avatar Feb 17 '21 15:02 coveralls

'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'

Alcaro avatar Feb 17 '21 15:02 Alcaro

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 avatar Feb 17 '21 16:02 furious

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

furious avatar Mar 01 '21 03:03 furious

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)

p4plus2 avatar Mar 09 '21 10:03 p4plus2