Write a subroutine which satisfies the following contract: Name: Twos Comp Input
ID: 653544 • Letter: W
Question
Write a subroutine which satisfies the following contract: Name: Twos Comp Input: R10 contains a 16bit signed integer Output: R11 contains the Two's Complement of the contents of R10 The subroutine should save all local variables on the stack. 2's Complement = l's Complement + 1 Use the instructions bit.w and bis.w/bic.w to test and set/clear individual bits Do not use the inv.w or sub.w instructions in this subroutine for testing or setting the bits. You can use sub.w to reserve space on the stack. Test this subroutine in the main code by using an input equal to 28 (decimal) and storing the output in a variable named "result". Use loops for repeated tasks. Include pseudo code (subroutine only), flow chart (subroutine)Explanation / Answer
.cdecls C,LIST,"msp430.h" ; Include device header file
;???????????????????????????????????????????????????????????????????????????????
.data
x: .space 2
;???????????????????????????????????????????????????????????????????????????????
.text ; Assemble into program memory
.retain ; Override ELF conditional linking
; and retain current section
.retainrefs ; Additionally retain any sections
; that have references to current
; section
;???????????????????????????????????????????????????????????????????????????????
RESET mov.w #__STACK_END,SP ; Initialize stackpointer
StopWDT mov.w #WDTPW|WDTHOLD,&WDTCTL ; Stop watchdog timer
;???????????????????????????????????????????????????????????????????????????????
; Main loop here
mov #0, &x
mov #0, R5
cond_label:
cmp #10, R5
jge break
add R5, &x
inc R5
jmp cond_label
break:
loop: jmp loop
;???????????????????????????????????????????????????????????????????????????????
;???????????????????????????????????????????????????????????????????????????????
; Stack Pointer definition
;???????????????????????????????????????????????????????????????????????????????
.global __STACK_END
.sect .stack
;???????????????????????????????????????????????????????????????????????????????
; Interrupt Vectors
;???????????????????????????????????????????????????????????????????????????????
.sect ".reset" ; MSP430 RESET Vector
.short RESET
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.