我正在尝试使用MIPS编写条形码128解码器。我想将每个字符的模式存储为整数组合成一个数组。它看起来像这样:
.data #file data.asm
code_0: .word 0x6CC
code_1: .word 0x66C
code_2: .word 0x666
code_3: .word 0x498
code_4: .word 0x48C
code_5: .word 0x44C
code_6: .word 0x4C8
code_7: .word 0x4C4
code_8: .word 0x464
code_9: .word 0x648
code_10: .word 0x644
code_11: .word 0x624
code_12: .word 0x59C
code_13: .word 0x4DC
code_14: .word 0x4CE
code_15: .word 0x5CC
code_16: .word 0x4EC
code_17: .word 0x4E6
code_18: .word 0x672
code_19: .word 0x65C
code_20: .word 0x64E
code_21: .word 0x6E4
code_22: .word 0x674
code_23: .word 0x76E
code_24: .word 0x74C
code_25: .word 0x72C
code_26: .word 0x726
code_27: .word 0x764
code_28: .word 0x734
code_29: .word 0x732
code_30: .word 0x6D8
code_31: .word 0x6C6
code_32: .word 0x636
code_33: .word 0x518
code_34: .word 0x458
code_35: .word 0x446
code_36: .word 0x588
code_37: .word 0x468
code_38: .word 0x462
code_39: .word 0x688
code_40: .word 0x628
code_41: .word 0x622
code_42: .word 0x5B8
code_43: .word 0x58E
code_44: .word 0x46E
code_45: .word 0x5D8
code_46: .word 0x5C6
code_47: .word 0x476
code_48: .word 0x776
code_49: .word 0x68E
code_50: .word 0x62E
code_51: .word 0x6E8
code_52: .word 0x6E2
code_53: .word 0x6EE
code_54: .word 0x758
code_55: .word 0x746
code_56: .word 0x716
code_57: .word 0x768
code_58: .word 0x762
code_59: .word 0x71A
code_60: .word 0x77A
code_61: .word 0x642
code_62: .word 0x78A
code_63: .word 0x530
code_64: .word 0x50C
code_65: .word 0x4B0
code_66: .word 0x486
code_67: .word 0x42C
code_68: .word 0x426
code_69: .word 0x590
code_70: .word 0x584
code_71: .word 0x4D0
code_72: .word 0x4C2
code_73: .word 0x434
code_74: .word 0x432
code_75: .word 0x612
code_76: .word 0x650
code_77: .word 0x7BA
code_78: .word 0x614
code_79: .word 0x47A
code_80: .word 0x53C
code_81: .word 0x4BC
code_82: .word 0x49E
code_83: .word 0x5E4
code_84: .word 0x4F4
code_85: .word 0x4F2
code_86: .word 0x7A4
code_87: .word 0x794
code_88: .word 0x792
code_89: .word 0x6DE
code_90: .word 0x6F6
code_91: .word 0x7B6
code_92: .word 0x578
code_93: .word 0x51E
code_94: .word 0x45E
code_95: .word 0x5E8
code_96: .word 0x5E2
code_97: .word 0x7A8
code_98: .word 0x7A2
code_99: .word 0x5DE
code_100: .word 0x5EE
code_101: .word 0x75E
code_102: .word 0x7AE
code_103: .word 0x684
code_104: .word 0x690
code_105: .word 0x69C
code_106: .word 0x18EB
array_of_codes:
.word code_0, code_1, code_2, code_3, code_4, code_5, code_6, code_7, code_8, code_9, code_10,
code_11, code_12, code_13, code_14, code_15, code_16, code_17, code_18, code_19, code_20,
code_21, code_22, code_23, code_24, code_25, code_26, code_27, code_28, code_29, code_30
code_31, code_32, code_33, code_34, code_35, code_36, code_37, code_38, code_39, code_40,
code_41, code_42, code_43, code_44, code_45, code_46, code_47, code_48, code_49, code_50,
code_51, code_52, code_53, code_54, code_55, code_56, code_57, code_58, code_59, code_60
code_61, code_62, code_63, code_64, code_65, code_66, code_67, code_68, code_69, code_70,
code_71, code_72, code_73, code_74, code_75, code_76, code_77, code_78, code_79, code_80,
code_81, code_82, code_83, code_84, code_85, code_86, code_87, code_88, code_89, code_90,
code_91, code_92, code_93, code_94, code_95, code_96, code_97, code_98, code_99, code_100,
code_101, code_102, code_103, code_104, code_105, code_106
这是非常方便的方法,因为在条形码128中,每个字符被编码为连续黑条和白色空格的宽度序列(如果我们考虑'!'符号,则为fe,即11001101100或222122,具体取决于符号,表示我们有宽度为2的黑色条,宽度为2的白色空格,宽度为2的黑色条,宽度为1的白色空间等。我的问题是从包含所有代码的数组中读取值。下面的代码应该完成这项工作:
la $t5, array_of_codes
lw $t4, ($t5) # now t4 should store the code_0 value, which is 0x6CC
但是t4寄存器存储的值不等于0x6CC(code_0值)。奇怪的是,每次我将t5上的地址递增4(以获得数组中的下一个整数),读取到t4的值也会增加4个字节,并参考旧的值(因为您可以看到值变化很大,每两个值之间没有4字节差异模式)。我认为我在某个地方犯了一个关键的错误,可能是在错误的地址而不是文字上运行。如果您需要参考我的整个代码的样子,我将在下面发布。任何帮助将不胜感激。
.data
.include "data.asm"
buffer: .space 2
header: .space 54
width: .word 600
height: .word 50
code_buffer: .space 7
special_code_buffer: .space 8
output: .space 100
dsc_error_msg: .asciiz "File descriptor error!"
bitmap_error_msg: .asciiz "Loaded file is not a bitmap!"
format_error_msg: .asciiz "Loaded bmp resolution is not 24-bit!"
size_error_msg: .asciiz "Wrong file size! Allowed size is 600x50."
checksum_error_msg: .asciiz "Wrong checksum value!"
char_code_error_msg: .asciiz "Character code not found!"
no_barcode_error_msg: .asciiz "There is no barcode in the picture!"
no_black_pixel: .asciiz "There is no barcode in the bitmap!"
placeholder: .asciiz "Black pixel found!"
fpath: .asciiz "/home/mateusz/develop/projects/ecoar/mips/Code-128-Decoder/abcd.bmp"
.text
open_file:
li $v0, 13
la $a0, fpath
li $a1, 0
li $a2, 0
syscall
bltz $v0, dsc_file_error
move $s0, $v0
li $v0, 14
move $a0, $s0
la $a1, header
li $a2, 54
syscall
li $t0, 0x4D42
lhu $t1, header
bne $t0, $t1, bitmap_error
lw $t0, width
lw $s1, header+18
bne $t0, $s1, size_error
lw $t0, height
lw $s2, header+22
bne $t0, $s2, size_error
li $t0, 24
lb $t1, header+28
bne $t0, $t1, format_error
lw $s3, header+34
li $v0, 9
move $a0, $s3
syscall
move $s4, $v0
li $v0, 14
move $a0, $s0
move $a1, $s4
move $a2, $s3
syscall
close_file:
li $v0, 16
move $a0, $s0
syscall
set_up:
move $t9, $s4
li $s4, 0
li $t7, 30 #line_number
li $t6, 1800
mul $t7, $t7, $t6
addu $t9, $t9, $t7
li $t8, 0 # chcecking if we passed full row
la $a3, output
xor $s4, $s4, $s4
xor $s7, $s7, $s7
xor $s6, $s6, $s6
xor $s5, $s5, $s5
look_for_black:
lb $t0, ($t9)
beqz $t0, black_found
iterate:
addiu $t9, $t9, 3
addiu $t8, $t8, 1
beq $t8, 599, no_barcode
j look_for_black
black_found:
li $t1, 1
la $t7, ($t9)
find_width:
addiu $t7, $t7, 3
lb $t0, ($t7)
bnez $t0, end_of_bar
addiu $t1, $t1, 1
j find_width
end_of_bar:
divu $t6, $t1, 2
move $t7, $t6 # width of the thinest bar in pixels
mulu $t6, $t7, 5 # firt width which exceeds limit of 5
pre_prepare:
xor $s0, $s0, $s0 # pattern
xor $s1, $s1, $s1 # number of shifts
li $s2, 1
li $s3, 0
prepare:
li $t1, 0
lb $t2, ($t9) # current color
get_bar:
lb $t0, ($t9)
addiu $t1, $t1, 1
addiu $t9, $t9, 3
move $t3, $t2 # hold color
beq $t1, $t7, bar_obtained
j get_bar
bar_obtained:
beq $t2, 0xffffff, white_bar
beq $t2, 0x000000, black_bar
white_bar:
or $s0, $s0, $s3
sll $s0, $s0, 1
addiu $s1, $s1, 1
beq $s1, 10, pattern_finished
j prepare
black_bar:
or $s0, $s0, $s2
sll $s0, $s0, 1
addiu $s1, $s1, 1
beq $s1, 10, pattern_finished
j prepare
pattern_finished:
li $t1, 0
la $t5, array_of_codes
compare:
lw $t4, ($t5)
beq $s0, $t4, equal
bne $s0, $t4, not_equal
equal:
beq $t1, 103, start
addiu $s4, $s4, 1
move $s5, $t1
mulu $s6, $s4, $s5
addu $s7, $s7, $s6
addiu $t1, $t1, 32
sb $t1, ($a3)
addiu $a3, $a3, 1
xor $s0, $s0, $s0
xor $s1, $s1, $s1
j prepare
start:
addu $s4, $s4, $t1
j prepare
not_equal:
addiu $t1, $t1, 1
beq $t1, 105, possible_stop
addiu $t5, $t5, 4
j compare
possible_stop:
xor $s0, $s0, $s0
xor $s1, $s1, $s1
get_bars:
li $t1, 0
lb $t2, ($t9)
get_additional_bars:
lb $t0, ($t9)
addiu $t1, $t1, 1
addiu $t9, $t9, 3
move $t3, $t2 # hold color
beq $t1, $t7, additional_obtained
j get_bar
additional_obtained:
beq $t2, 0xffffff, white_bar_add
beq $t2, 0x000000, black_bar_add
white_bar_add:
or $s0, $s0, $s3
sll $s0, $s0, 1
addiu $s1, $s1, 1
beq $s1, 2, finalize
j get_bars
black_bar_add:
or $s0, $s0, $s3
sll $s0, $s0, 1
addiu $s1, $s1, 1
beq $s1, 2, finalize
j get_bars
finalize:
la $a1, array_of_codes+424
lw $a2, ($a1)
bne $s0, $a2, wrong_code
beq $s0, $a2, match
match:
subu $s7, $s7, $s6
li $t4, 103
divu $s7, $t4
xor $t4, $t4, $t4
mfhi $t4
bne $t4, $s5 wrong_checksum
finish:
li $t3, '\0'
subiu $a3, $a3, 1
sb $t3, ($a3)
exit_success:
li $v0, 4
la $a0, output
syscall
li $v0, 10
syscall
no_barcode:
li $v0, 4
la $a0, no_barcode_error_msg
syscall
j exit
wrong_checksum:
li $v0, 4
la $a0, checksum_error_msg
syscall
j exit
wrong_code:
li $v0, 4
la $a0, char_code_error_msg
syscall
j exit
black_not_found:
li $v0, 4
la $a0, no_black_pixel
syscall
j exit
dsc_file_error:
li $v0, 4
la $a0, dsc_error_msg
syscall
j exit
bitmap_error:
li $v0, 4
la $a0, bitmap_error_msg
syscall
j exit
size_error:
li $v0, 4
la $a0, size_error_msg
syscall
j exit
format_error:
li $v0, 4
la $a0, format_error_msg
syscall
j exit
exit:
li $v0, 10
syscall