Need help with string reverse function ; ; string_reverse.asm .include \"m2560de
ID: 3592783 • Letter: N
Question
Need help with string reverse function ; ; string_reverse.asm .include "m2560def.inc" ;SPH, SPL, RAMEND, etc. are defined in "m2560def.inc" .cseg ; initialize the stack pointer ldi r16, low(RAMEND) out SPL, r16 ldi r16, high(RAMEND) out SPH, r16 ; prepare the parameters X and Z ldi ZH, high(src<<1) ldi ZL, low(src<<1) ldi XH, high(dest) ldi XL, low(dest) ;call subroutine void strcpy(src, dest) call strcpy ;call subroutine: str_reverse(dest, mesg) ;write your code here ; program ends here done: jmp done ; This subroutine (function) copies a null-terminated string ; starting at some (source) program memory address to a location starting ; at some (destination) memory address. ; The memory addresses are passed to the subroutine via the X and Z pointers strcpy: ; copy the string from source (Z) to destination (X) next_char: lpm r23, Z+ st X+, r23 tst r23 brne next_char strcpy_done: ret ; Write your str_reverse subroutine and comments here. ; Using push and pop, reverse the c-string and store at a different memory ; location. The memory addresses are passed to the subroutine via pointers. str_reverse: ; write your code here src: .db "Hello, world!", 0 ; c-string format .dseg .org 0x200 dest: .byte 14 reversed: .byte 14
Explanation / Answer
include "m2560def.inc" ;SPH, SPL, RAMEND, etc. are defined in "m2560def.inc" .cseg ; initialize the stack pointer ldi r16, low(RAMEND) out SPL, r16 ldi r16, high(RAMEND) out SPH, r16 ; prepare the parameters X and Z ldi ZH, high(srcRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.