Assembly Programming - PowerPoint PPT Presentation

1 / 12
About This Presentation
Title:

Assembly Programming

Description:

ret. restore. Execution always starts at the label main. Trap back to the operating system ... o0. call printf. nop. ret. restore .section '.data' fmt: .asciz ' ... – PowerPoint PPT presentation

Number of Views:53
Avg rating:3.0/5.0
Slides: 13
Provided by: mah138
Category:

less

Transcript and Presenter's Notes

Title: Assembly Programming


1
Assembly Programming
2
SPARC Language Program Skeleton
  • .global main
  • main
  • save sp, -96, sp
  • ... other code ...
  • mov 1, g1
  • ta 0
  • .global main
  • main
  • save sp, -96, sp
  • ... other code ...
  • ret
  • restore

Execution always starts at the label main
Trap back to the operating system
Normal exit procedure
3
SPARC Instruction
  • Standard Format
  • ltopgt src_reg, src_reg, dest_reg
  • ltopgt src_reg, immediate, dest_reg ! -4096
    lt immediate lt 4096
  • synthetic instructions
  • clr reg
    gt or g0, g0, reg
  • mov immediate, dest_reg gt or
    g0, immediate, dest_reg
  • mov src_reg, dest_reg gt or
    g0, src_reg, dest_reg

4
Registers
  • g0 r0 (always zero)
  • g1 r1
  • g7 r7
  • o0 r8
  • o6 r14 sp
  • o7 r15 for return address
  • l0 r16
  • l7 r23
  • i0 r24
  • i6 r30 fp
  • i7 r31 for return address

5
Example
  • .global main
  • main
  • save sp,-96,sp
  • mov 9, l0
  • sub l0, 1, o0
  • sub l0, 7, o1
  • call .mul
  • nop
  • sub l0, 0xb, o1
  • call .div
  • nop
  • mov o0, l1
  • mov 1, g1
  • ta 0

6
SPARC control structures
  • Condition codes
  • N -- negative contains status of result
    from last instruction
  • Z -- zero
  • V -- overflow
  • C -- carry
  • Branches
  • ba
  • bneg
  • bg

7
Control Structure
  • while ( a lt 17 ) test
  • a a b cmp a_r,
    17
  • c bg done
  • nop
  • add
    a_r, b_r, a_r
  • add
    c_r, 1, c_r
  • ba
    test
  • nop
  • done

8
Control Structure
  • for ( a 1 a lt b a )
    mov 1,a_r
  • c a
    test

  • cmp a_r,b_r

  • bg done

  • nop
  • rewritten as while loop
    mov a_r, o0

  • mov c_r, o1
  • a 1
    call .mul
  • while ( a lt b )
    nop
  • c a
    mov o0, c_r
  • a
    add a_r, 1, a_r

  • ba test

  • nop

  • done

9
Control Structure
  • if ( (a b) gt c )
    add a_r, b_r, o0
  • a b
    cmp o0, c_r

  • ble next

  • nop

  • add a_r, b_r, a_r

  • next

10
Control Structure
  • if ( a ! b ) cmp
    a_r, b_r
  • c 1 be
    else_part
  • else nop
  • c 0 then_part

  • mov 1, c_r

  • ba next

  • nop
  • else_part

  • mov 0, c_r
  • next

11
Arrays
  • void prt_sum( int x, int n )
  • register int i, sum 0
  • for( i 0 i lt n i )
  • sum sum xi
  • printf("d\n",sum)

12
Arrays
  • .global main
  • main
  • save sp, -96, sp
  • clr l0
  • clr l1
  • mov i0, l
  • loop
  • cmp l0, i1
  • bge done
  • nop
  • ld l2, o0
  • add l1, o0, l1
  • add l2, 4, l2
  • inc l0
  • ba loop
  • nop
  • done
  • set fmt, o0
  • mov l1, o0
Write a Comment
User Comments (0)
About PowerShow.com