Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9201943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:08:23+00:00 2026-06-17T23:08:23+00:00

I thought it will be easy to explain on specific example, i understood beq

  • 0

I thought it will be easy to explain on specific example, i understood beq works like if r9==r10 that statement gives a call for the label which is shown on the same line but i didn’t understand others exactly.

START:
.word 0
.word INSTR1
INSTR1:
.word 1
.word 77
.word INSTR2
INSTR2:
.word 2
.word 15
.word FIN
FIN:
.word 3

acc:
    .word 0


.text

.global main

main:   movia r8, START
    movia r9, acc

myloop: movi r10, 1
    ldw r11, 0x0(r8)
    beq r11, r0, clear
    beq r11, r10, add
    addi r10, r10, 1
    beq r11, r10, sub
    addi r10, r10, 1
    beq r11, r10, exit
    br fail

clear:  stw r0, 0x0(r9)
    ldw r8, 0x4(r8)
    br myloop

add:    ldw r12, 0x0(r9)
    ldw r13, 0x4(r9)
    addi r12, r12, r13
    stw r12, 0x0(r9)
    ldw r8, 0x8(r8)
    br myloop

sub:    ldw r12, 0x0(r9)
    ldw r13, 0x4(r9)
    sub r12, r12, r13
    stw r12, 0x0(r9)
    ldw r8, 0x8(r8)
    br myloop

exit:   ret

fail:   movia r12, 0xFFFFFFFF
    stw r12, 0x0(r9)
    ret
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T23:08:24+00:00Added an answer on June 17, 2026 at 11:08 pm

    Movia is a pseudo statement, that loads a 32-bit immediate address to a register.
    As the instruction width in NIOS is fixed to 32-bit it happens using two instructions:

    "load_high_16_bits_and_clear_the_lower_part, register, #imm16_hi"
    "or_register_with_16_bit_immediate_at_the_lower_part, register, #imm16_lo"
    

    Because NIOS provides orhi instruction, the same can be performed as:

    "load_lower_bits_and_clear_the_rest register, #imm16"
    "orhi register, #imm16_hi_bits"
    

    movi == move immediate. Again, that instruction can accept only #imm16.

    ldw = load “word” == 32 bits. The address is calculated by adding an immediate to a register. In this case the instruction set allows only 14 bits of displacement.

    stw = store “word” == 32 bits.

    addi = add immediate: register = register + #imm_16

    The instruction set reference uses a Greek symbol “sigma” before the immediate as a notation for a function doing “sign extension”, which means copying the most significant bit in the immediate all over the 32-bit register (or temporary value) allowing also signed immediates. (notice sig_ned vs. sig_ma).

    EDIT

    The call mechanism in NIOS also needs some attention: it uses a “sliding window register mechanism”, which means that the processor has e.g. 64 or 256 registers out of which only 32 registers are simultaneously visible. The lower 16 registers, IIRC, are “global” and the 16 upper registers shift 4 or 8 registers every time a call or a return is made.

    This means that the register bank automatically “allocates” some temporary variables, which become the input parameters of the next function call when the window is shifted. Again, IIRC, call copies the return address to one particular register (e.g. r31) at call, which is seen as r23 (or vice versa) at the called function. There ‘ret’ would mean to jump to ‘r23’ and shift the register window back. Likewise, one could return several registers back to the caller.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to set layout something like What i thought that i will have
First I thought that the problem will be very easy to solve, but it
I am trying to do something that I thought would be very easy with
This is a really easy one that I thought would be easily found on
I've got a couple questions that I think will be quite easy for someone
I have a project that I thought was going to be relatively easy, but
I thought BeautifulSoup will be able to handle malformed documents, but when I sent
This will be probable quite odd question. But i thought I will give it
I thought the following script will create div element but I got nothing output
AS the subject outlines, the background div will not show, I thought you needed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.