搜索此博客

显示标签为“代码”的博文。显示所有博文
显示标签为“代码”的博文。显示所有博文

2012年9月5日星期三

Jump to uncertain (run-time determined) address in assembly language

Sometimes I want program to jump to uncertain (run-time determined) address like function pointer does in C language. For example, a function table. If the chip supports "jsr" with register indirect addressing, like H8, it will be as simple as
    jsr   @er0
But on the core I am using called "Flex RISC", 8bit, performs as peripheral device in an ARM based SoC, thers is only one "jsr" instruction which using immediate addressing. Branch instructions (brXX) and jmp instruction do the same.
At last I found there is another instruction changes PC pointer, "rts". It pop PC point from stack. So here is the way out:
    ...
; variable SomeAddr keeps SomeFunc's sddress
    ld     a1, SomeAddr
    ld     a2, SomeAddr + 1
    jsr    CallByAddr
    ...

SomeFunc:
    ...
    rts          ; this "rts" will exactly returns from the "jsr".

CallByAddr:
    psh    a2
    psh    a1
    rts          ; this "rts" will pop a2a1 to PC that makes SomeFunc called.

2008年7月16日星期三

Vim的2html脚本

用Vim直接转HTML,很方便。

:runtime! syntax/2html.vim

Windows版要把“/”反过来写成“\”。

2008年7月11日星期五

用Cscope帮助Vim浏览代码


  1. 建立cscope.out的脚本makecs.sh,makecs.sh 。

  2. #/bin/bash

    TEMPLATE=cscope.XXXXXX

    if [ -n "$1" ]; then
    cd "$1";

    TEMP_FILE=$(mktemp "$TEMPLATE")
    find -regex '.*\.\([ch]\|[ch][px][px]\|pgc\)' | grep -v '.svn' > "$TEMP_FILE"
    cscope -b -i "$TEMP_FILE"

    rm "$TEMP_FILE"
    else
    echo "makecs <dir>"
    exit 1
    fi

  3. Cscope插件

  4. autoload_cscope,放在./vim/plugin/或者/usr/share/vim/vim70/plugin/。我下的是0.3,78行的“find c”改成了“find s”,在175、176行加入了*.pgc。
  5. 用法

  6. C-] = 查定义

    C-\, s = 查引用

    C-\, c = 查调用