Making "Good" Assembly Code

You can talk about almost anything that you want to on this board.

Moderator: Moderators

lidnariq
Posts: 9510
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: Making "Good" Assembly Code

Post by lidnariq » Sat Jul 25, 2020 2:40 pm

I smiled.

Pokun
Posts: 1492
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: Making "Good" Assembly Code

Post by Pokun » Sat Jul 25, 2020 4:59 pm

I was distracted by thinking how Ior was pronounced in English (turns out it's the same). It was funny the second look though if that helps!

calima
Posts: 1160
Joined: Tue Oct 06, 2015 10:16 am

Re: Making "Good" Assembly Code

Post by calima » Sun Jul 26, 2020 1:27 am

I still don't get what's funny about it, or how Mario RPG and Eeyore are related to anything. Sure in English his name sounds like error, but where is the funny part or connection.

93143
Posts: 1197
Joined: Fri Jul 04, 2014 9:31 pm

Re: Making "Good" Assembly Code

Post by 93143 » Sun Jul 26, 2020 1:30 am

The discussion was about the pronunciation of XOR. Most people on here will be aware that 65xx uses a different mnemonic for exclusive-or, namely EOR.

So I took a screenshot of the Exor battle from SMRPG and replaced the boss appropriately.

I dunno; it was hilarious to me when I thought of it...

calima
Posts: 1160
Joined: Tue Oct 06, 2015 10:16 am

Re: Making "Good" Assembly Code

Post by calima » Sun Jul 26, 2020 2:15 am

Oh. It's been 20 years since I played Mario RPG, not like I can remember boss names.

User avatar
aa-dav
Posts: 92
Joined: Tue Apr 14, 2020 9:45 pm
Location: Russia

Re: Making "Good" Assembly Code

Post by aa-dav » Sun Jul 26, 2020 7:44 am

93143 wrote:
Sun Jul 26, 2020 1:30 am
...
So I took a screenshot of the Exor battle from SMRPG and replaced the boss appropriately.
...
Lol! I had no chance to understand it because translation of Winnie-the-Pooh in my native language uses different naming. But now I find it hilarious!

Offtopic:
By the way, Oxford Dictionary in the article about term 'pooh' https://www.lexico.com/definition/pooh says:
exclamation
informal
1Used to express disgust at an unpleasant smell.
...
noun
1 (also poo)
Excrement.
Eh... But, but... 'Winnie-the-Pooh' contains word 'pooh'! Again, this name was translated in my native language like 'Winnie-the-Fluff' and nothing like 'excrements' in this name exists. And then I discovered real name I was like 'WTF??'.
Does it really sound with suspicious smell for natives in english??

tepples
Posts: 22020
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Making "Good" Assembly Code

Post by tepples » Sun Jul 26, 2020 2:00 pm

Most people don't associate Winnie the Pooh with feces unless someone specifically points it out. Hence "Winnie the Shit" in joke books and "Cooking with Poo" on photo manipulation sites (before Saiyuud Diwong's Thai cookbook usurped the name). The animation accompanying the OP to The Many Adventures of Winnie the Pooh implies that the name "pooh" reflects the bear attempting to direct air up to the nose to shoo away an insect that has landed there.

But putting a stuffed bear in a bathroom and then pointing it out later as "Pooh was watching you poo" is still funny.

User avatar
aa-dav
Posts: 92
Joined: Tue Apr 14, 2020 9:45 pm
Location: Russia

Re: Making "Good" Assembly Code

Post by aa-dav » Sun Jul 26, 2020 8:07 pm

tepples wrote:
Sun Jul 26, 2020 2:00 pm
Most people don't associate Winnie the Pooh with feces unless someone specifically points it out. Hence "Winnie the Shit" in joke books and "Cooking with Poo" on photo manipulation sites (before Saiyuud Diwong's Thai cookbook usurped the name). The animation accompanying the OP to The Many Adventures of Winnie the Pooh implies that the name "pooh" reflects the bear attempting to direct air up to the nose to shoo away an insect that has landed there.

But putting a stuffed bear in a bathroom and then pointing it out later as "Pooh was watching you poo" is still funny.
Thank you for explanation! I was really wondering about it. :)

turboxray
Posts: 83
Joined: Thu Oct 31, 2019 12:56 am

Re: Making "Beautiful" Assembly Code

Post by turboxray » Sun Jul 26, 2020 9:40 pm

Oziphantom wrote:
Thu Jul 23, 2020 12:13 am
Mov is an Intel thing
Someone hasn't coded for other processors haha. MOV/MOVE is used for more than just intel assembly syntax.



I'm not particularly a fan of LD, ST, and the different variations of it, but it's better than LDA/LDX/LDY, etc. Those really should have been LD #$10, A... ST A, var2.. etc.


Some of the macros I use for HuC6280

startup:

Code: Select all

startup:
        ;................................
        ;Main initialization routine.
        InitialStartup
        CallFarWide init_audio
        CallFarWide init_video

        stz $2000
        tii $2000,$2001,$2000

        ;................................
        ;Set video parameters
        VCE.reg LOW_RES|H_FILTER_ON
        VDC.reg HSR  , #$0202
        VDC.reg HDR  , #$031F
        VDC.reg VSR  , #$0F02
        VDC.reg VDR  , #$00EF
        VDC.reg VDE  , #$0003
        VDC.reg DCR  , #AUTO_SATB_ON
        VDC.reg CR   , #$0000
        VDC.reg SATB , #$7F00
        VDC.reg MWR  , #SCR64_32

        IRQ.control IRQ2_ON|VIRQ_ON|TIRQ_ON

        TIMER.port  _7.00khz
        TIMER.cmd   TMR_OFF

        MAP_BANK #MAIN, MPR6
        jmp MAIN
main..

Code: Select all

MAIN:
        ;................................
        ;Turn display on
        VDC.reg CR , #(BG_ON|SPR_OFF|VINT_ON|HINT_OFF)

        ;................................
        ;Load font
        loadCellToVram Font, $1000
        loadCellToCram.BG Font, 0

        ;................................
        ;Clear map
        jsr ClearScreen.64x32

        ;...............................
        ; TIRQ is already enabled, but TIMER needs to be as well
        TIMER.port  _7.00khz
        TIMER.cmd   TMR_ON

        ;...............................
        ; Reset the variables for the music/sfx engine
        CallFar HuTrackEngine.Init


        ;...............................
        ; Set the DDA routine and music engine ISRs
        ISR.setVector TIMER_VEC , HuTrackEngine.IRQ
        ISR.setVecMask TIMER_VEC

        ISR.setVector VDC_VSYNC , HuTrackEngine.EngineCall
        ISR.setVecMask VDC_VSYNC

        MOVE.w #VDC.vsync.rtn, HuTrack.returnVec


        ;...............................
        ; load in song,
        LEA.l test_song, $8000, EAX0
        CallFar HuTrackEngine.QueueSong

        LEA.l test_song.waveforms, $6000, EAX0
        CallFar HuTrackEngine.loadWaveformPack

        LEA.l test_song.samples, $8000, EAX0
        CallFar HuTrackEngine.loadSamplePack



        ;................................
        ;start the party
        Interrupts.enable

        ;................................
        ; Print string to (X,Y) coords
        PRINT_STR_i "Init build",2,3

        WAITVBLANK 0
        MOVE.b #$00, <EAX0.l
        CallFar HuTrackEngine.playSong

main_loop:

        WAITVBLANK 0
        CallFar HuTrackEngine.Process     ;//TODO <- call this manually for now
      bra main_loop
An example of a small function:

Code: Select all

;...............................................
; Input EAX0.l
HuTrackEngine.playSong:

        MOVE.b <EAX0.l, current_song
        MOVE.b <EAX0.l, IX
        AND.b  #$7f, <HuTrack.Status, <HuTrack.Playback

        PUSHBANK.2 MPR4
        MAP_BANK.2 song_bank,x , MPR4
        
        MOVE.sw song_ptr, IX, <R1
        LEA   <R1, #$8000, <R1


    rts
I have a huge set of macros like this for PC-Engine 65x code. The AND.b macro can take two or three arguments. If it takes three, then the third argument is the destination rather than the second arg.

The PCE has a built in MMU, so an LEA macro instruction was definitely needed.

The macros support .b, .w, .l (24bit), and .dw (32bit). They also support ADD.b.w when you need to add a byte value to a word value. Any combinations of those .b, .w., .l, .dw types. The effective address can be almost anything.. including register pairs A, A:X, A:Y, X:Y, and A:X:Y (24bit).

Split types on the 65x is pretty popular for speed, so I haven't that with prefixing an "s" in front of the type. So MOVE.w and MOVE.sw both handle word as the source and destination, but .sw in the macro appends ".lo" and ".hi" to labels. You define a var.lo and as var.hi, and just pass in a var... like MOVE.sw #$1234, var. For long (24bit) it's .lo, .hi, and .up. For .dw or double word (32bit), it's the same as long but adds ".tp".

The MOVE.sw song_ptr, IX, <R1 macro knows that the 2nd argument means to do (label).lo,x with <R1 and (label).hi,x with <R1+1.

I can do something like ADD.b.sl <delta, X_pos for an 8bit + 24bit -> 24bit operation. delta is an 8bit fixed point and X_pos is a 16:8 fixed point value. I have ADDS for signed extensions.

Most of the time the macros are cycle count efficient, but that's not always case (they don't care if something is already in A, X, or Y). Since the PCE's 6280 is 7.16mhz, losing a couple of cycles here and there doesn't really impact anything. The goal is code readability. Code that really needs attention to cycle counting, will have little or no macros in it.

Oziphantom
Posts: 861
Joined: Tue Feb 07, 2017 2:03 am

Re: Making "Good" Assembly Code

Post by Oziphantom » Mon Jul 27, 2020 6:47 am

Are you a m68K programmer?

What other 8080/8085/8086 era CPUs use MOV? MOVE is 68K but MOVE is not MOV.

If you want to code 6502 that way could just use WLA-DX ;) Personally I like the idea of not typing as much but I see my self loosing an hour or so a day as I stare at the code and then realize I forgot an s on the ws

User avatar
TmEE
Posts: 753
Joined: Wed Feb 13, 2008 9:10 am
Location: Estonia, Rapla city (50 and 60Hz compatible :P)
Contact:

Re: Making "Good" Assembly Code

Post by TmEE » Mon Jul 27, 2020 7:53 am

SuperH and ARM use MOV syntax too. I'm one of those who like LD, but because it is less to type and sort of makes more sense.

XOR I have seen as such from all the electronics things, there never has been EOR in any books etc. so seeing it always made me think "why is it EOR and not XOR" lol. I pronounce it as "ksor" as mentioned before in this thread, "x" = "ks" sound in 99.9% cases.

Oziphantom
Posts: 861
Joined: Tue Feb 07, 2017 2:03 am

Re: Making "Good" Assembly Code

Post by Oziphantom » Tue Jul 28, 2020 1:07 am

SuperH is from the 90s, ARM is 85 which also puts it well post Intel's chips and growth. It would be fair to say they were influenced by Intel's naming scheme. Although Acorn used 6502 CPUs so they might just wanted to be different.

User avatar
aa-dav
Posts: 92
Joined: Tue Apr 14, 2020 9:45 pm
Location: Russia

Re: Making "Good" Assembly Code

Post by aa-dav » Tue Jul 28, 2020 1:19 am

I wonder is there any assembler using C syntax?
That is:

Code: Select all

PORT_CONSOLE    = $FFFF
      sp  = $FF00

      pc  = start
    
mark  dw  0

; string_input
; in: r0 - string buffer
;     r1 - max buffer size
; out: 
string_input  r3  = r0    ; remember beginning
.loop    r2  =? [ PORT_CONSOLE ]
    pc  = .loop @z
    r2  <?> 13
    pc  = .end @z  ; if CR
    r2  <?> 8
    pc  = .backsp @z  ; if BS
    r1  =? r1
    pc  = .overfl @z  ; if buffer overflow
    ; accept symbol
    [ PORT_CONSOLE ] = r2
    r1  =-1 r1
    [ r0 ]  = r2
    r0  =+1 r0
    pc  = .loop    ; continue input
    ; backspace
.backsp    r0  <?> r3
    pc  = .loop @z  ; ignore del at start of line
    [ PORT_CONSOLE ] = r2
    [ PORT_CONSOLE ] = 32  ; erase prev symbol at (windows) console...
    [ PORT_CONSOLE ] = r2
    r1  =+1 r1
    r0  =-1 r0
    pc  = .loop
    ; overflow
.overfl    pc  = .loop ; just continue
    ; end
.end    [ r0 ]  = 0
    ret

; string_print
; in: r0 - string buffer
string_print  r1  =? [ r0 ]
    ret @z
    r0  =+1 r0
    [ PORT_CONSOLE ] = r1
    pc  = string_print

; string_len  
; in:  r0 - string buffer
; out:  r0 - length of the string
string_len  r1  = 0
.loop    r2  = [ r0 ]
    pc  = .end @z
    r0  =+1 r0
    r1  =+1 r1
    pc  = .loop
.end    r0  = r1
    ret

start    
  r0  = $0001
  r1  = $1000
  r0  &= r1
  [ mark ] = r0
  
    r0  = msg1
    call  string_print
    r0  = buf
    r1  = 10
    call  string_input
    [ PORT_CONSOLE ] = 10

    r0  = msg2
    call   string_print
    r0  = buf
    call  string_print
    r0  = CrLf
    call  string_print

    dw  0
buf    ds  12 $AAAA
msg1    dw  "Enter command: " 0
msg2    dw  "You entered this text: " 0
CrLf    dw  13 10 0
where

Code: Select all

call arg
; is shortcut for:
[ sp ] =+2 pc
pc = arg
and

Code: Select all

ret
; is shortcut for
pc = [ sp ]
That is main idea is using for arichmetic and logical operations C-like syntax.
In fact code above is my experiment of 'virtual processor' which I called 'Simpleton' and which contains instructions with syntax X ?= Y only where ? is ALU instruction char. It always gets right operand (and possibly left one for 2-op instruction), pass it through ALU with instruction code and writes to left operand.
But it was my very old dream to write not 'mov/ld/copy', but A = B, A += [ addr ], R4 -= data8 and so on... :)

Pokun
Posts: 1492
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: Making "Good" Assembly Code

Post by Pokun » Wed Jul 29, 2020 6:50 am

I've seen many old assembly languages using various variations of MOVE, but I think most of them stole it from the Intel processors no? It seems to be absent in 4040 though.

I personally prefer the 65x and Z80 mnemonics, and I see the 65x mnemonics constantly being 3 characters as an advantage. I'm a little annoyed that Rockwell and Hudson destroyed this symmetry by adding instructions with more characters in their variants. So does Motorola and some 65816 assemblers using .b and .w prefixes on mnemonics.

I've been told X is pronounced like Z when it's in the beginning of a word in English. The Japanese seems to have adopted this and even does this for things like Francisco Xavier (nevermind that the Spanish/Basque sound for J/X doesn't exists in Japanese).

lidnariq
Posts: 9510
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: Making "Good" Assembly Code

Post by lidnariq » Wed Jul 29, 2020 11:13 am

<off-topic> Words that were borrowed directly from Greek into English usually pronounce an initial X as Z, such as xylophone, xeroscape, and xenon. "Xavier" should probably be "Shave-ee-er" but English just loves stealing words from other languages and pronouncing them differently.

Post Reply