how can I write the assembly language to count on total number of characters of
ID: 3883417 • Letter: H
Question
how can I write the assembly language to count on total number of characters of given string in assembly language?(relate MSP430)
#include "msp430.h"
ORG 0FF00h
mystr DB "Welcome to Aeroclub Programming @JLC215!"
NAME main
PUBLIC main
ORG 0FFFEh
DC16 init
RSEG CSTACK
RSEG CODE
init: MOV #SFE(CSTACK), SP
main: NOP
MOV.W #WDTPW+WDTHOLD, &WDTCTL
BIS.B #0FFh, &P1DIR
BIS.B #0FFh, &P2DIR
MOV #mystr, R5
CLR.B R6
CLR.B R7 store total character
gonext: MOV.B @R5+, R6
CMP #0, R6
JEQ lend
INC R7
CMP.B #'a', R6
CMP.B #'{', R6
JMP gonext
lend:
MOV.B R7, &P2OUT
BIS.W #LPM4, SR
NOP
END
Explanation / Answer
#include "msp430.h" ; #define controlled include file
ORG 0FF00h
myStr DB "Welcome to Aeroclub Programming @JLC215!" ; the string is placed on the stack
; the null character is automatically added after the '!'
NAME main ; module name
PUBLIC main ; make the main label visible
; outside this module
ORG 0FFFEh
DC16 init ; set reset vector to 'init' label
RSEG CSTACK ; pre-declaration of segment
RSEG CODE ; place program in 'CODE' segment
init: MOV #SFE(CSTACK), SP ; set up stack
main: NOP ; main program
MOV.W #WDTPW+WDTHOLD,&WDTCTL ; Stop watchdog timer
BIS.B #0FFh,&P1DIR ; configure P1.x output
MOV.W #myStr, R4 ; load the starting address of the string into the
register R4
CLR.B R5 ; register R5 will serve as a counter
gnext: MOV.B @R4+, R6 ; get a new character
CMP #0,R6
JEQ lend ; go to the end
INC R5 ; increment counter
JMP gnext
lend: MOV.B R5,&P1OUT ; Set all P1 pins
BIS.W #LPM4,SR ; LPM4
NOP ; Required only for debugger
END
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.