• MIPS汇编之绘图


    没想到MIPS的模拟器WinMIPS64居然还有绘图功能,我忍不住想试一试。

    基本思想就是,给定要绘制的像素点的坐标(X)和坐标(Y)以及RGB值,通过调用WinMIPS64提供的5号IO功能在屏幕上绘制像素点

    于是按照这里的教程

    WinMIPS64 — Documentation Summary (dcu.ie)

    Values written to CONTROL are as follows:
    CONTROLUsage

    Write Operations

     

    1

    set DATA to an unsigned integer for output

    2

    set DATA to a signed integer for output

    3

    set DATA to a floating point value for output

    4

    set DATA to the memory address of a string for output

    5

    set DATA+5 to the x coordinate, DATA+4 to the y coordinate, and DATA to the RGB colour for the pixel (using, respectively, byte, byte and word32 stores)

    Read Operations

     

    8

    read DATA (either an integer or a floating-point value) from the terminal/keyboard

    9

    read one byte from DATA, no character is echoed

    Other Operations

     

    6

    clear the terminal screen

    7

    clear the graphics screen

    根据上表,我应该往DATA中传4字节的RGB值,再往DATA+4和DATA+5里传X和Y的值

    最后把CONTROL功能号置为5,这样该软件就可以为我自动绘制图像了。

    我写出了如下的IO程序,期望可以在屏幕上打印出若干个指定色彩的像素点。

     1 .data
     2 CONTROL:  .word32  0x10000
     3 DATA:  .word32  0x10008
     4 #positionx:   .byte  1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17
     5 rgb:          .word32   0xD2B48C
     6 len:         .word   0xff
     7 #hello:       .asciiz  'hello
    hello
    '
     8 .text
     9 # initiate
    10 ld    $t1,len($zero)
    11 daddi    $t2,$zero,5  # control word = 5  plot function 
    12 lwu     $t3,CONTROL($zero) # $t3 is control port
    13 lwu     $t4,DATA($zero)  # $t4 is data port 
    14 lwu       $t6,rgb($zero)
    15 #daddi    $t7,$zero,hello
    16 #daddi    $t6,$zero,0
    17 sw     $t6,($t4)
    18 #sd      $t7,($t4)
    19 # loop 
    20 loop:
    21 daddi   $t1,$t1,-1
    22 slt        $t5,$t1,$zero
    23 bnez      $t5,end
    24 
    25 sb      $t1,4($t4)
    26 sb      $t1,5($t4)
    27 
    28 sd      $t2,($t3)  #  plot
    29 j  loop
    30 
    31 end:
    32 halt

    上面的代码看起来是不是有点乱?

    确实,博主写代码的时候思路不够清晰,而且其中含有部分用于测试的代码。

    比如

    #hello:       .asciiz  'hello
    hello
    '
    
    #daddi    $t7,$zero,hello
    
    #sd      $t7,($t4)

    这几行代码都是当时为了调试所加的

    因为博主不确定bug是那个部分引起的

    先跑一个hello程序,如果可以,说明IO功能调用应该没有问题,问题就出在RGB、X、Y的存取上

    我在跑hello程序的时候,程序是这样的:

     1 .data
     2 CONTROL:  .word32  0x10000
     3 DATA:  .word32  0x10008
     4 #positionx:   .byte  1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17
     5 rgb:          .word32   0xD2B48C# ,0xFFD700,0x00FF7F, 0xEE82EE,0x8B7765
     6 len:         .word   0xff
     7 hello:       .asciiz  'hello
    '
     8 .text
     9 # initiate
    10 ld    $t1,len($zero)
    11 daddi    $t2,$zero,4  # control word = 5  plot function 
    12 lwu     $t3,CONTROL($zero) # $t3 is control port
    13 lwu     $t4,DATA($zero)  # $t4 is data port 
    14 lwu       $t6,rgb($zero)
    15 daddi    $t7,$zero,hello
    16 #daddi    $t6,$zero,0
    17 #sw     $t6,($t4)
    18 sd      $t7,($t4)
    19 # loop 
    20 loop:
    21 daddi   $t1,$t1,-1
    22 slt        $t5,$t1,$zero
    23 bnez      $t5,end
    24 
    25 sb      $t1,4($t4)
    26 sb      $t1,5($t4)
    27 
    28 sd      $t2,($t3)  #  plot
    29 j  loop
    30 
    31 end:
    32 halt

    原本预计它应当输出255行的”hello“的,但是只输出了1行

    这是什么原因?

    我在仔细排查后,发现,是由于

    sb    $t1,4($t4)

    sb    $t1,4($4)

    使得DATA端口的4、5字节都被篡改了

    原本应该是0、0的

    现在变成了$t1的值

    当$t1是0xff到1的时候,都是错误的值,都无法输出

    只有当$t1为0的时候,才能正常输出,因此只能输出1个hello

    我将其修改过来,即删除上述的2行代码(或注释掉)

    发现程序的行为正确了。

    接下来我就开始进行图形绘制程序的测试。

    发现可以正常进行绘图操作,挺开心的。

    谢谢您的耐心阅读,本人博客写作能力有限,请读者斧正,留下你的宝贵建议,感激不尽!

  • 相关阅读:
    Redis命令——小白学习 Redis 数据库日记(2017-06-13)
    Buses(形容城市公车交通情况)
    Things you need to prepare before going to airport
    bathroom words
    this指针
    友元
    成员对象和封闭类
    静态成员变量和静态成员函数、 常量对象和常量成员函数
    C++类
    shell选择语句、循环语句
  • 原文地址:https://www.cnblogs.com/studentWangqy/p/14032974.html
Copyright © 2020-2023  润新知