0

I have array of words in .data

array: .word 0x0000012, 0x0000d42f, ..... , 0 // 0 indicates end of array.

I need to print each word's count of '1's and then at the end print the maximum count of '1's .

I tried moving the word to a temporary register and then shift it left, each iteration, but it doesn't work ..

################### Data segment ###################
.data
    x: .word 0x00000001, 0x00000007, 0x0000ffff, 0x20430066, 0
    bits: .word 0
################### Code segment ###################
.text
.globl main
  main:

    lw $a0, x
    li $v0,1
    syscall

    li $v0,10 # exit
    syscall

That code works. but it only refers to the first word in x. I don't know how to get to the second WORD in x

BVtp
  • 2,308
  • 2
  • 29
  • 68
  • Please add your actual assembly code to your question. – Tripp Kinetics Aug 05 '15 at 18:17
  • @TrippKinetics , I've edited my post. Thank you – BVtp Aug 05 '15 at 18:22
  • You probably want to load the *address* of `x` into a register, via `la $reg, x`, then successively load form that address `lw $otherreg, 0($reg)`, and increment the address `addi $reg, $reg, 4`. Finding the popcount is *your* homework, but I know it can be frustrating to get started. – EOF Aug 05 '15 at 18:45

0 Answers0