Jump to content
IGNORED

Help with 8048 assembly.


Recommended Posts

I'm trying to make a random number from 0-255 change to between 48-127. And I can't. The computer just completely ignores my code and does its own thing. Why does it ignore my code?

get_new_o
    mov r0,#seed
    mov a,@r0
    mov r1,#letter_o_y_position
    rr a
    add a,#30h
    mov @r1,a    
    
    call gfxon
    call waitvsync

    ret

This SHOULD divide letter_o_y_position by 2 and then add 48 but it won't listen to me and the y position still is between 0-255, which I don't want it to be at!

 

Link to comment
Share on other sites

Member · Posted

Try this and let me know if it helps.

get_new_o
    mov r0, #seed            ; Load seed address into R0
    mov a, @r0               ; Load seed value into A
    swap a                   ; Swap nibbles
    anl a, #0x0F             ; Mask higher nibble, this approximates /16
    add a, #48               ; Add 48 to scale it between 48-127
    mov r1, #letter_o_y_position ; Load y position address into R1
    mov @r1, a               ; Store new value at y position
    
    call gfxon
    call waitvsync

    ret

 

Link to comment
Share on other sites

Thanks for the help! I got a working code now. I just changed one thing.

get_new_o

    mov r0, #seed            ; Load seed address into R0
    mov a, @r0               ; Load seed value into A
    swap a                   ; Swap nibbles
    anl a, #63             
    add a, #48               ; Add 48 to scale it between 48-127
    mov r1, #letter_o_y_position ; Load y position address into R1
    mov @r1, a               ; Store new value at y position
    
    call gfxon
    call waitvsync

	ret

I just changed anl #15 to anl #63 because I noticed that with it set to #15, all the locations were near the top of the screen. Changing it to 63 made some more in the middle.

xvso13.png.7c9ca4f677c1edad302d0f2661bdf359.png

 

Link to comment
Share on other sites

Member · Posted

FYI, if my post helped, I copied your post to ChatGPT.  I have the paid tier which gets you access to the latest model.

So I have no clue how that code helped. ChatGPT figured it out.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Welcome to VGS!

    Play, Make, Collect.

    Here at VGS all kinds of gamers are welcome, and that includes you!

    Join the conversation!

×
×
  • Create New...