#!/usr/bin/bash

# The purpose of the script is to track down what function the assembly code calls.
# for example, for the call in the two lines below:
#    211a:	4b05      	ldr	r3, [pc, #20]	; (2130 <io_write+0x34>)
#    211c:	4798      	blx	r3
# the user would have to run `asm_find_func.sh listing_file.lss 2130` and they
# would learn that the function called here is "assert".

num=$(grep $2: "$1" | cut -f2)
numhex=0x$(echo "ibase=16; obase=10; ${num^^}-1" | bc)
numhexwide=$(printf '%08x\n' $numhex)
grep $numhexwide "$1"
